TopFieldDocCollectorpublic class TopFieldDocCollector extends TopDocCollector A {@link HitCollector} implementation that collects the top-sorting
documents, returning them as a {@link TopFieldDocs}. This is used by {@link
IndexSearcher} to implement {@link TopFieldDocs}-based search.
This may be extended, overriding the collect method to, e.g.,
conditionally invoke super() in order to filter which
documents are collected. |
Constructors Summary |
---|
public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits)Construct to collect a given number of hits.
super(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits));
|
Methods Summary |
---|
public void | collect(int doc, float score)
if (score > 0.0f) {
totalHits++;
hq.insert(new FieldDoc(doc, score));
}
| public org.apache.lucene.search.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());
|
|