TopScoreDocCollector (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.search, class: TopScoreDocCollector

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 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, totalHitsRelation`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `LeafCollector`
  `getLeafCollector(LeafReaderContext context)`
  Create a new `collector` to collect the given context.
  `protected TopDocs`
  `newTopDocs(ScoreDoc[] results, int start)`
  Returns a `TopDocs` instance containing the given results.
  `protected void`
  `populateResults(ScoreDoc[] results, int howMany)`
  Populates the results array with the ScoreDoc instances.
  `protected void`
  `pruneLeastCompetitiveHitsTo(int keep)`
  Prune the least competitive hits until the number of candidates is less than or equal to `keep`.
  `ScoreMode`
  `scoreMode()`
  Indicates what features are required from the scorer.
  `protected int`
  `topDocsSize()`
  The number of valid PQ entries

  ### Methods inherited from class org.apache.lucene.search.TopDocsCollector

  `getTotalHits, topDocs, topDocs, topDocs`

  ### 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

  `setWeight`

- ## Method Details

  - ### 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>`

  - ### scoreMode

    public ScoreMode scoreMode()
    Description copied from interface: `Collector`
    Indicates what features are required from the scorer.

  - ### getLeafCollector

    public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException
    Description copied from interface: `Collector`
    Create a new `collector` to collect the given context.
    Parameters:
      `context` - next atomic reader context
    Throws:
      `IOException`

  - ### topDocsSize

    protected int topDocsSize()
    Description copied from class: `TopDocsCollector`
    The number of valid PQ entries
    Overrides:
      `topDocsSize` in class `TopDocsCollector<ScoreDoc>`

  - ### populateResults

    protected void populateResults(ScoreDoc[] results, int howMany)
    Description copied from class: `TopDocsCollector`
    Populates the results array with the ScoreDoc instances. This can be overridden in case a different ScoreDoc type should be returned.
    Overrides:
      `populateResults` in class `TopDocsCollector<ScoreDoc>`

  - ### pruneLeastCompetitiveHitsTo

    protected void pruneLeastCompetitiveHitsTo(int keep)
    Description copied from class: `TopDocsCollector`
    Prune the least competitive hits until the number of candidates is less than or equal to `keep`. This is typically called before `TopDocsCollector.populateResults(org.apache.lucene.search.ScoreDoc[], int)` to ensure we are at right pos.
    Overrides:
      `pruneLeastCompetitiveHitsTo` in class `TopDocsCollector<ScoreDoc>`