Package org.apache.lucene.search
Class TopScoreDocCollector
- java.lang.Object
-
- org.apache.lucene.search.Collector
-
- org.apache.lucene.search.TopDocsCollector<ScoreDoc>
-
- org.apache.lucene.search.TopScoreDocCollector
-
public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc>
ACollector
implementation that collects the top-scoring hits, returning them as aTopDocs
. This is used byIndexSearcher
to implementTopDocs
-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
andFloat.NEGATIVE_INFINITY
are not valid scores. This collector will not properly collect hits with such scores.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TopScoreDocCollector
create(int numHits, boolean docsScoredInOrder)
Creates a newTopScoreDocCollector
given the number of hits to collect and whether documents are scored in order by the inputScorer
tosetScorer(Scorer)
.static TopScoreDocCollector
create(int numHits, ScoreDoc after, boolean docsScoredInOrder)
Creates a newTopScoreDocCollector
given the number of hits to collect, the bottom of the previous page, and whether documents are scored in order by the inputScorer
tosetScorer(Scorer)
.void
setNextReader(AtomicReaderContext context)
Called before collecting from eachAtomicReaderContext
.void
setScorer(Scorer scorer)
Called before successive calls toCollector.collect(int)
.-
Methods inherited from class org.apache.lucene.search.TopDocsCollector
getTotalHits, topDocs, topDocs, topDocs
-
Methods inherited from class org.apache.lucene.search.Collector
acceptsDocsOutOfOrder, collect
-
-
-
-
Method Detail
-
create
public static TopScoreDocCollector create(int numHits, boolean docsScoredInOrder)
Creates a newTopScoreDocCollector
given the number of hits to collect and whether documents are scored in order by the inputScorer
tosetScorer(Scorer)
.NOTE: The instances returned by this method pre-allocate a full array of length
numHits
, and fill the array with sentinel objects.
-
create
public static TopScoreDocCollector create(int numHits, ScoreDoc after, boolean docsScoredInOrder)
Creates a newTopScoreDocCollector
given the number of hits to collect, the bottom of the previous page, and whether documents are scored in order by the inputScorer
tosetScorer(Scorer)
.NOTE: The instances returned by this method pre-allocate a full array of length
numHits
, and fill the array with sentinel objects.
-
setNextReader
public void setNextReader(AtomicReaderContext context)
Description copied from class:Collector
Called before collecting from eachAtomicReaderContext
. All doc ids inCollector.collect(int)
will correspond toIndexReaderContext.reader()
. AddAtomicReaderContext.docBase
to the currentIndexReaderContext.reader()
's internal document id to re-base ids inCollector.collect(int)
.- Specified by:
setNextReader
in classCollector
- Parameters:
context
- next atomic reader context
-
setScorer
public void setScorer(Scorer scorer) throws java.io.IOException
Description copied from class:Collector
Called before successive calls toCollector.collect(int)
. Implementations that need the score of the current document (passed-in toCollector.collect(int)
), should save the passed-in Scorer and call scorer.score() when needed.
-
-