Package org.apache.lucene.search
Class TopScoreDocCollector
- All Implemented Interfaces:
Collector
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, totalHitsRelation -
Method Summary
Modifier and TypeMethodDescriptiongetLeafCollector(LeafReaderContext context) Create a newcollectorto collect the given context.protected TopDocsnewTopDocs(ScoreDoc[] results, int start) Returns aTopDocsinstance containing the given results.protected voidpopulateResults(ScoreDoc[] results, int howMany) Populates the results array with the ScoreDoc instances.protected voidpruneLeastCompetitiveHitsTo(int keep) Prune the least competitive hits until the number of candidates is less than or equal tokeep.Indicates what features are required from the scorer.protected intThe number of valid PQ entriesMethods inherited from class org.apache.lucene.search.TopDocsCollector
getTotalHits, topDocs, topDocs, topDocs
-
Method Details
-
newTopDocs
Description copied from class:TopDocsCollectorReturns aTopDocsinstance containing the given results. Ifresultsis 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:
newTopDocsin classTopDocsCollector<ScoreDoc>
-
scoreMode
Description copied from interface:CollectorIndicates what features are required from the scorer. -
getLeafCollector
Description copied from interface:CollectorCreate a newcollectorto collect the given context.- Parameters:
context- next atomic reader context- Throws:
IOException
-
topDocsSize
protected int topDocsSize()Description copied from class:TopDocsCollectorThe number of valid PQ entries- Overrides:
topDocsSizein classTopDocsCollector<ScoreDoc>
-
populateResults
Description copied from class:TopDocsCollectorPopulates the results array with the ScoreDoc instances. This can be overridden in case a different ScoreDoc type should be returned.- Overrides:
populateResultsin classTopDocsCollector<ScoreDoc>
-
pruneLeastCompetitiveHitsTo
protected void pruneLeastCompetitiveHitsTo(int keep) Description copied from class:TopDocsCollectorPrune the least competitive hits until the number of candidates is less than or equal tokeep. This is typically called beforeTopDocsCollector.populateResults(org.apache.lucene.search.ScoreDoc[], int)to ensure we are at right pos.- Overrides:
pruneLeastCompetitiveHitsToin classTopDocsCollector<ScoreDoc>
-