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

Package org.apache.lucene.search.grouping

# Class TopGroupsCollector<T>

java.lang.Object
org.apache.lucene.search.SimpleCollector
org.apache.lucene.search.grouping.SecondPassGroupingCollector<T>
org.apache.lucene.search.grouping.TopGroupsCollector<T>

Type Parameters:
  `T` - the type of the group value

All Implemented Interfaces:
  `Collector`, `LeafCollector`

public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T>
A second-pass collector that collects the TopDocs for each group, and returns them as a `TopGroups` object

- ## Field Summary

  ### Fields inherited from class org.apache.lucene.search.grouping.SecondPassGroupingCollector

  `groupReducer, groups, groupSelector, totalGroupedHitCount, totalHitCount`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TopGroupsCollector(GroupSelector<T> groupSelector, Collection<SearchGroup<T>> groups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getMaxScores)`
  Create a new TopGroupsCollector

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TopGroups<T>`
  `getTopGroups(int withinGroupOffset)`
  Get the TopGroups recorded by this collector

  ### Methods inherited from class org.apache.lucene.search.grouping.SecondPassGroupingCollector

  `collect, doSetNextReader, getGroupSelector, scoreMode, setScorer`

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

  `getLeafCollector`

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

  ### Methods inherited from interface org.apache.lucene.search.LeafCollector

  `collect, collectRange, competitiveIterator, finish`

- ## Constructor Details

  - ### TopGroupsCollector

    public TopGroupsCollector(GroupSelector<T> groupSelector, Collection<SearchGroup<T>> groups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getMaxScores)
    Create a new TopGroupsCollector
    Parameters:
      `groupSelector` - the group selector used to define groups
      `groups` - the groups to collect TopDocs for
      `groupSort` - the order in which groups are returned
      `withinGroupSort` - the order in which documents are sorted in each group
      `maxDocsPerGroup` - the maximum number of docs to collect for each group
      `getMaxScores` - if true, record the maximum score for each group

- ## Method Details

  - ### getTopGroups

    public TopGroups<T> getTopGroups(int withinGroupOffset)
    Get the TopGroups recorded by this collector
    Parameters:
      `withinGroupOffset` - the offset within each group to start collecting documents