/// <summary> Populates the results array with the ScoreDoc instaces. This can be /// overridden in case a different ScoreDoc type should be returned. /// </summary> protected internal virtual void PopulateResults(ScoreDoc[] results, int howMany) { for (int i = howMany - 1; i >= 0; i--) { results[i] = (ScoreDoc) pq.Pop(); } }
public virtual int Compare(ScoreDoc i, ScoreDoc j) { if (i.doc < j.doc) return - 1; if (i.doc > j.doc) return 1; return 0; }
public virtual int Compare(ScoreDoc i, ScoreDoc j) { if (i.score > j.score) return - 1; if (i.score < j.score) return 1; return 0; }
// javadoc inherited public override TopDocs TopDocs() { FieldSortedHitQueue fshq = (FieldSortedHitQueue) hq; ScoreDoc[] scoreDocs = new ScoreDoc[fshq.Size()]; for (int i = fshq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs[i] = fshq.FillFields((FieldDoc) fshq.Pop()); return new TopFieldDocs(totalHits, scoreDocs, fshq.GetFields(), fshq.GetMaxScore()); }
/// <summary> Returns whether <code>a</code> is less relevant than <code>b</code>.</summary> /// <param name="a">ScoreDoc /// </param> /// <param name="b">ScoreDoc /// </param> /// <returns> <code>true</code> if document <code>a</code> should be sorted after document <code>b</code>. /// </returns> public override bool LessThan(System.Object a, System.Object b) { ScoreDoc docA = (ScoreDoc)a; ScoreDoc docB = (ScoreDoc)b; // run comparators int n = comparators.Length; int c = 0; for (int i = 0; i < n && c == 0; ++i) { c = (fields[i].reverse)?comparators[i].Compare(docB, docA):comparators[i].Compare(docA, docB); } // avoid random sort order that could lead to duplicates (bug #31241): if (c == 0) { return(docA.doc > docB.doc); } return(c > 0); }
public int Compare(ScoreDoc i, ScoreDoc j) { System.String is_Renamed = index[i.doc]; System.String js = index[j.doc]; if ((System.Object)is_Renamed == (System.Object)js) { return(0); } else if (is_Renamed == null) { return(-1); } else if (js == null) { return(1); } else { return(collator.Compare(is_Renamed.ToString(), js.ToString())); } }
// javadoc inherited public override void Collect(int doc, float score) { if (score > 0.0f) { totalHits++; if (reusableSD == null) { reusableSD = new ScoreDoc(doc, score); } else if (score >= reusableSD.score) { // reusableSD holds the last "rejected" entry, so, if // this new score is not better than that, there's no // need to try inserting it reusableSD.doc = doc; reusableSD.score = score; } else { return ; } reusableSD = (ScoreDoc) hq.InsertWithOverflow(reusableSD); } }
public virtual System.IComparable SortValue(ScoreDoc i) { return((float)i.score); }
public virtual int Compare(ScoreDoc i, ScoreDoc j) { return cachedValues[i.doc].CompareTo(cachedValues[j.doc]); }
public int Compare(ScoreDoc i, ScoreDoc j) { System.String is_Renamed = index[i.doc]; System.String js = index[j.doc]; if ((System.Object) is_Renamed == (System.Object) js) { return 0; } else if (is_Renamed == null) { return - 1; } else if (js == null) { return 1; } else { return collator.Compare(is_Renamed.ToString(), js.ToString()); } }
public int Compare(ScoreDoc i, ScoreDoc j) { int fi = index.order[i.doc]; int fj = index.order[j.doc]; if (fi < fj) return - 1; if (fi > fj) return 1; return 0; }
public virtual System.IComparable SortValue(ScoreDoc i) { return (float) i.score; }
public /*protected internal*/ override TopDocs NewTopDocs(ScoreDoc[] results, int start) { if (results == null) { results = EMPTY_SCOREDOCS; // Set maxScore to NaN, in case this is a maxScore tracking collector. maxScore = System.Single.NaN; } // If this is a maxScoring tracking collector and there were no results, return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue) pq).GetFields(), maxScore); }
/// <summary>The top-scoring hits. </summary> public virtual TopDocs TopDocs() { ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs[i] = (ScoreDoc) hq.Pop(); float maxScore = (totalHits == 0)?System.Single.NegativeInfinity:scoreDocs[0].score; return new TopDocs(totalHits, scoreDocs, maxScore); }
public virtual System.IComparable SortValue(ScoreDoc i) { return(index[i.doc]); }
public virtual System.IComparable SortValue(ScoreDoc i) { return(index.lookup[index.order[i.doc]]); }
public virtual System.IComparable SortValue(ScoreDoc i) { return((double)fieldOrder[i.doc]); }
public virtual System.IComparable SortValue(ScoreDoc i) { return (System.Int32) i.doc; }
public virtual System.IComparable SortValue(ScoreDoc i) { return(cachedValues[i.doc]); }
public override TopDocs Search(Weight weight, Filter filter, int nDocs) { HitQueue hq = new HitQueue(nDocs, false); int totalHits = 0; for (int i = 0; i < searchables.Length; i++) { // search each searcher TopDocs docs = searchables[i].Search(weight, filter, nDocs); totalHits += docs.TotalHits; // update totalHits ScoreDoc[] scoreDocs = docs.ScoreDocs; for (int j = 0; j < scoreDocs.Length; j++) { // merge scoreDocs into hq ScoreDoc scoreDoc = scoreDocs[j]; scoreDoc.doc += starts[i]; // convert doc if (!hq.Insert(scoreDoc)) break; // no more scores > minScore } } ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs2[i] = (ScoreDoc) hq.Pop(); float maxScore = (totalHits == 0)?System.Single.NegativeInfinity:scoreDocs2[0].score; return new TopDocs(totalHits, scoreDocs2, maxScore); }
// prevents instantiation private TopScoreDocCollector(int numHits) : base(new HitQueue(numHits, true)) { // HitQueue implements getSentinelObject to return a ScoreDoc, so we know // that at this point top() is already initialized. pqTop = (ScoreDoc)pq.Top(); }
public int Compare(ScoreDoc i, ScoreDoc j) { long li = fieldOrder[i.doc]; long lj = fieldOrder[j.doc]; if (li < lj) return - 1; if (li > lj) return 1; return 0; }
/* * Only the following callback methods need to be overridden since * topDocs(int, int) calls them to return the results. */ protected internal override void PopulateResults(ScoreDoc[] results, int howMany) { if (fillFields) { // avoid casting if unnecessary. FieldValueHitQueue queue = (FieldValueHitQueue) pq; for (int i = howMany - 1; i >= 0; i--) { results[i] = queue.FillFields((Entry) queue.Pop()); } } else { for (int i = howMany - 1; i >= 0; i--) { Entry entry = (Entry) pq.Pop(); results[i] = new FieldDoc(entry.docID, entry.score); } } }
public int Compare(ScoreDoc i, ScoreDoc j) { double di = fieldOrder[i.doc]; double dj = fieldOrder[j.doc]; if (di < dj) return - 1; if (di > dj) return 1; return 0; }
public Result (string Term, Searcher searcher, ScoreDoc[] docs) { this.term = Term; this.searcher = searcher; this.docs = docs; }
/// <summary> A search implementation which spans a new thread for each /// Searchable, waits for each search to complete and merge /// the results back together. /// </summary> public override TopDocs Search(Weight weight, Filter filter, int nDocs) { HitQueue hq = new HitQueue(nDocs, false); int totalHits = 0; MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length]; for (int i = 0; i < searchables.Length; i++) { // search each searchable // Assume not too many searchables and cost of creating a thread is by far inferior to a search msta[i] = new MultiSearcherThread(searchables[i], weight, filter, nDocs, hq, i, starts, "MultiSearcher thread #" + (i + 1)); msta[i].Start(); } for (int i = 0; i < searchables.Length; i++) { try { msta[i].Join(); } catch (System.Threading.ThreadInterruptedException ie) { // In 3.0 we will change this to throw // InterruptedException instead SupportClass.ThreadClass.Current().Interrupt(); throw new System.SystemException(ie.Message, ie); } System.IO.IOException ioe = msta[i].GetIOException(); if (ioe == null) { totalHits += msta[i].Hits(); } else { // if one search produced an IOException, rethrow it throw ioe; } } ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs[i] = (ScoreDoc) hq.Pop(); float maxScore = (totalHits == 0)?System.Single.NegativeInfinity:scoreDocs[0].score; return new TopDocs(totalHits, scoreDocs, maxScore); }
public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort) { FieldDocSortedHitQueue hq = null; int totalHits = 0; float maxScore = System.Single.NegativeInfinity; for (int i = 0; i < searchables.Length; i++) { // search each searcher TopFieldDocs docs = searchables[i].Search(weight, filter, n, sort); // If one of the Sort fields is FIELD_DOC, need to fix its values, so that // it will break ties by doc Id properly. Otherwise, it will compare to // 'relative' doc Ids, that belong to two different searchers. for (int j = 0; j < docs.fields.Length; j++) { if (docs.fields[j].GetType() == SortField.DOC) { // iterate over the score docs and change their fields value for (int j2 = 0; j2 < docs.ScoreDocs.Length; j2++) { FieldDoc fd = (FieldDoc) docs.ScoreDocs[j2]; fd.fields[j] = (System.Int32) (((System.Int32) fd.fields[j]) + starts[i]); } break; } } if (hq == null) hq = new FieldDocSortedHitQueue(docs.fields, n); totalHits += docs.TotalHits; // update totalHits maxScore = System.Math.Max(maxScore, docs.GetMaxScore()); ScoreDoc[] scoreDocs = docs.ScoreDocs; for (int j = 0; j < scoreDocs.Length; j++) { // merge scoreDocs into hq ScoreDoc scoreDoc = scoreDocs[j]; scoreDoc.doc += starts[i]; // convert doc if (!hq.Insert(scoreDoc)) break; // no more scores > minScore } } ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs2[i] = (ScoreDoc) hq.Pop(); return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore); }
// prevents instantiation private TopScoreDocCollector(int numHits):base(new HitQueue(numHits, true)) { // HitQueue implements getSentinelObject to return a ScoreDoc, so we know // that at this point top() is already initialized. pqTop = (ScoreDoc) pq.Top(); }
public int Compare(ScoreDoc i, ScoreDoc j) { float fi = fieldOrder[i.doc]; float fj = fieldOrder[j.doc]; if (fi < fj) return - 1; if (fi > fj) return 1; return 0; }
public /*protected internal*/ override TopDocs NewTopDocs(ScoreDoc[] results, int start) { if (results == null) { return EMPTY_TOPDOCS; } // We need to compute maxScore in order to set it in TopDocs. If start == 0, // it means the largest element is already in results, use its score as // maxScore. Otherwise pop everything else, until the largest element is // extracted and use its score as maxScore. float maxScore = System.Single.NaN; if (start == 0) { maxScore = results[0].score; } else { for (int i = pq.Size(); i > 1; i--) { pq.Pop(); } maxScore = ((ScoreDoc) pq.Pop()).score; } return new TopDocs(totalHits, results, maxScore); }
public virtual System.IComparable SortValue(ScoreDoc i) { return (double) fieldOrder[i.doc]; }
/// <summary> Returns the documents in the rage [start .. start+howMany) that were /// collected by this collector. Note that if start >= pq.size(), an empty /// TopDocs is returned, and if pq.size() - start < howMany, then only the /// available documents in [start .. pq.size()) are returned.<br/> /// This method is useful to call in case pagination of search results is /// allowed by the search application, as well as it attempts to optimize the /// memory used by allocating only as much as requested by howMany.<br/> /// <b>NOTE:</b> you cannot call this method more than once for each search /// execution. If you need to call it more than once, passing each time a /// different range, you should call {@link #TopDocs()} and work with the /// returned {@link TopDocs} object, which will contain all the results this /// search execution collected. /// </summary> public TopDocs TopDocs(int start, int howMany) { // In case pq was populated with sentinel values, there might be less // results than pq.size(). Therefore return all results until either // pq.size() or totalHits. int size = totalHits < pq.Size()?totalHits:pq.Size(); // Don't bother to throw an exception, just return an empty TopDocs in case // the parameters are invalid or out of range. if (start < 0 || start >= size || howMany <= 0) { return NewTopDocs(null, start); } // We know that start < pqsize, so just fix howMany. howMany = System.Math.Min(size - start, howMany); ScoreDoc[] results = new ScoreDoc[howMany]; // pq's pop() returns the 'least' element in the queue, therefore need // to discard the first ones, until we reach the requested range. // Note that this loop will usually not be executed, since the common usage // should be that the caller asks for the last howMany results. However it's // needed here for completeness. for (int i = pq.Size() - start - howMany; i > 0; i--) { pq.Pop(); } // Get the requested results from pq. PopulateResults(results, howMany); return NewTopDocs(results, start); }
public virtual System.IComparable SortValue(ScoreDoc i) { return index.lookup[index.order[i.doc]]; }
/// <summary> Returns a {@link TopDocs} instance containing the given results. If /// <code>results</code> is null it means there are no results to return, /// either because there were 0 calls to collect() or because the arguments to /// topDocs were invalid. /// </summary> public /*protected internal*/ virtual TopDocs NewTopDocs(ScoreDoc[] results, int start) { return results == null?EMPTY_TOPDOCS:new TopDocs(totalHits, results); }
public virtual System.IComparable SortValue(ScoreDoc i) { return index[i.doc]; }
/// <summary>Constructs a TopDocs with a default maxScore=Float.NaN. </summary> internal TopDocs(int totalHits, ScoreDoc[] scoreDocs):this(totalHits, scoreDocs, System.Single.NaN) { }
public virtual System.IComparable SortValue(ScoreDoc i) { return cachedValues[i.doc]; }
/// <summary></summary> public TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore) { this.TotalHits = totalHits; this.ScoreDocs = scoreDocs; this.MaxScore = maxScore; }
public virtual System.IComparable SortValue(ScoreDoc i) { return((System.Int32)i.doc); }
public virtual int Compare(ScoreDoc i, ScoreDoc j) { return(cachedValues[i.doc].CompareTo(cachedValues[j.doc])); }