org.apache.lucene.search

## Class TopDocs

- java.lang.Object
- - org.apache.lucene.search.TopDocs

- Direct Known Subclasses:
    TopFieldDocs

      public class TopDocs
      extends Object

  Represents hits returned by `IndexSearcher.search(Query,int)`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `ScoreDoc[]` | `scoreDocs` The top hits for the query.
    `int` | `totalHits` The total number of hits for the query.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `float` | `getMaxScore()` Returns the maximum score value encountered.
    `static TopDocs` | `merge(int start, int topN, TopDocs[] shardHits, boolean setShardIndex)` Same as `merge(int, TopDocs[])` but also ignores the top `start` top docs.
    `static TopDocs` | `merge(int topN, TopDocs[] shardHits)` Returns a new TopDocs, containing topN results across the provided TopDocs, sorting by score.
    `static TopFieldDocs` | `merge(Sort sort, int start, int topN, TopFieldDocs[] shardHits, boolean setShardIndex)` Same as `merge(Sort, int, TopFieldDocs[])` but also ignores the top `start` top docs.
    `static TopFieldDocs` | `merge(Sort sort, int topN, TopFieldDocs[] shardHits)` Returns a new TopFieldDocs, containing topN results across the provided TopFieldDocs, sorting by the specified `Sort`.
    `void` | `setMaxScore(float maxScore)` Sets the maximum score value encountered.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### totalHits

          public int totalHits

      The total number of hits for the query.

    - #### scoreDocs

          public ScoreDoc[] scoreDocs

      The top hits for the query.

  - ### Constructor Detail

    - #### TopDocs

          public TopDocs(int totalHits,
                         ScoreDoc[] scoreDocs,
                         float maxScore)

  - ### Method Detail

    - #### getMaxScore

          public float getMaxScore()

      Returns the maximum score value encountered. Note that in case scores are not tracked, this returns `Float.NaN`.

    - #### setMaxScore

          public void setMaxScore(float maxScore)

      Sets the maximum score value encountered.

    - #### merge

          public static TopDocs merge(int topN,
                                      TopDocs[] shardHits)

      Returns a new TopDocs, containing topN results across the provided TopDocs, sorting by score. Each `TopDocs` instance must be sorted.
      See Also:
        `merge(int, int, TopDocs[], boolean)`
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### merge

          public static TopDocs merge(int start,
                                      int topN,
                                      TopDocs[] shardHits,
                                      boolean setShardIndex)

      Same as `merge(int, TopDocs[])` but also ignores the top `start` top docs. This is typically useful for pagination. Note: If `setShardIndex` is true, this method will assume the incoming order of `shardHits` reflects each shard's index and will fill the `ScoreDoc.shardIndex`, otherwise it must already be set for all incoming `ScoreDoc`s, which can be useful when doing multiple reductions (merges) of TopDocs.
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### merge

          public static TopFieldDocs merge(Sort sort,
                                           int topN,
                                           TopFieldDocs[] shardHits)

      Returns a new TopFieldDocs, containing topN results across the provided TopFieldDocs, sorting by the specified `Sort`. Each of the TopDocs must have been sorted by the same Sort, and sort field values must have been filled (ie, `fillFields=true` must be passed to `TopFieldCollector.create(org.apache.lucene.search.Sort, int, boolean, boolean, boolean)`).
      See Also:
        `merge(Sort, int, int, TopFieldDocs[], boolean)`
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### merge

          public static TopFieldDocs merge(Sort sort,
                                           int start,
                                           int topN,
                                           TopFieldDocs[] shardHits,
                                           boolean setShardIndex)

      Same as `merge(Sort, int, TopFieldDocs[])` but also ignores the top `start` top docs. This is typically useful for pagination. Note: If `setShardIndex` is true, this method will assume the incoming order of `shardHits` reflects each shard's index and will fill the `ScoreDoc.shardIndex`, otherwise it must already be set for all incoming `ScoreDoc`s, which can be useful when doing multiple reductions (merges) of TopDocs.
      WARNING: This API is experimental and might change in incompatible ways in the next release.

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