org.apache.lucene.search
Class TopScoreDocCollector

java.lang.Object
  extended by org.apache.lucene.search.Collector
      extended by org.apache.lucene.search.TopDocsCollector<ScoreDoc>
          extended by org.apache.lucene.search.TopScoreDocCollector

public abstract class TopScoreDocCollector
extends TopDocsCollector<ScoreDoc>

A Collector implementation that collects the top-scoring hits, returning them as a TopDocs. This is used by IndexSearcher to implement TopDocs-based search. Hits are sorted by score descending and then (when the scores are tied) docID ascending. When you create an instance of this collector you should know in advance whether documents are going to be collected in doc Id order or not.

NOTE: The values Float.NaN and {Float#NEGATIVE_INFINITY} are not valid scores. This collector will not properly collect hits with such scores.


Field Summary
 
Fields inherited from class org.apache.lucene.search.TopDocsCollector
EMPTY_TOPDOCS, pq, totalHits
 
Method Summary
static TopScoreDocCollector create(int numHits, boolean docsScoredInOrder)
          Creates a new TopScoreDocCollector given the number of hits to collect and whether documents are scored in order by the input Scorer to setScorer(Scorer).
protected  TopDocs newTopDocs(ScoreDoc[] results, int start)
          Returns a TopDocs instance containing the given results.
 void setNextReader(IndexReader reader, int base)
          Called before collecting from each IndexReader.
 void setScorer(Scorer scorer)
          Called before successive calls to Collector.collect(int).
 
Methods inherited from class org.apache.lucene.search.TopDocsCollector
getTotalHits, populateResults, topDocs, topDocs, topDocs
 
Methods inherited from class org.apache.lucene.search.Collector
acceptsDocsOutOfOrder, collect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static TopScoreDocCollector create(int numHits,
                                          boolean docsScoredInOrder)
Creates a new TopScoreDocCollector given the number of hits to collect and whether documents are scored in order by the input Scorer to setScorer(Scorer).

NOTE: The instances returned by this method pre-allocate a full array of length numHits, and fill the array with sentinel objects.


newTopDocs

protected TopDocs newTopDocs(ScoreDoc[] results,
                             int start)
Description copied from class: TopDocsCollector
Returns a TopDocs instance containing the given results. If results 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.

Overrides:
newTopDocs in class TopDocsCollector<ScoreDoc>

setNextReader

public void setNextReader(IndexReader reader,
                          int base)
Description copied from class: Collector
Called before collecting from each IndexReader. All doc ids in Collector.collect(int) will correspond to reader. Add docBase to the current IndexReaders internal document id to re-base ids in Collector.collect(int).

Specified by:
setNextReader in class Collector
Parameters:
reader - next IndexReader

setScorer

public void setScorer(Scorer scorer)
               throws IOException
Description copied from class: Collector
Called before successive calls to Collector.collect(int). Implementations that need the score of the current document (passed-in to Collector.collect(int)), should save the passed-in Scorer and call scorer.score() when needed.

Specified by:
setScorer in class Collector
Throws:
IOException


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.