Package org.apache.lucene.search
Class TopScoreDocCollector
- java.lang.Object
-
- org.apache.lucene.search.TopDocsCollector<ScoreDoc>
-
- org.apache.lucene.search.TopScoreDocCollector
-
- All Implemented Interfaces:
Collector
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.
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.search.TopDocsCollector
EMPTY_TOPDOCS, pq, totalHits
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TopScoreDocCollector
create(int numHits)
Creates a newTopScoreDocCollector
given the number of hits to collect and whether documents are scored in order by the inputScorer
toLeafCollector.setScorer(Scorer)
.static TopScoreDocCollector
create(int numHits, ScoreDoc after)
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
toLeafCollector.setScorer(Scorer)
.boolean
needsScores()
Indicates if document scores are needed by this collector.protected TopDocs
newTopDocs(ScoreDoc[] results, int start)
Returns aTopDocs
instance containing the given results.-
Methods inherited from class org.apache.lucene.search.TopDocsCollector
getTotalHits, populateResults, topDocs, topDocs, topDocs, topDocsSize
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.search.Collector
getLeafCollector
-
-
-
-
Method Detail
-
create
public static TopScoreDocCollector create(int numHits)
Creates a newTopScoreDocCollector
given the number of hits to collect and whether documents are scored in order by the inputScorer
toLeafCollector.setScorer(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)
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
toLeafCollector.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 aTopDocs
instance containing the given results. Ifresults
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 classTopDocsCollector<ScoreDoc>
-
needsScores
public boolean needsScores()
Description copied from interface:Collector
Indicates if document scores are needed by this collector.- Returns:
true
if scores are needed.
-
-