FileDocCategorySizeDatePackage
TopFieldDocCollector.javaAPI DocApache Lucene 2.0.02136Fri May 26 09:54:18 BST 2006org.apache.lucene.search

TopFieldDocCollector

public 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.

Fields Summary
Constructors Summary
public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits)
Construct to collect a given number of hits.

param
reader the index to be searched
param
sort the sort criteria
param
numHits the maximum number of hits to collect

    super(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits));
  
Methods Summary
public voidcollect(int doc, float score)

    if (score > 0.0f) {
      totalHits++;
      hq.insert(new FieldDoc(doc, score));
    }
  
public org.apache.lucene.search.TopDocstopDocs()

    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());