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

Package org.apache.lucene.search.grouping

# Class AllGroupHeadsCollectorManager<T>

java.lang.Object
org.apache.lucene.search.grouping.AllGroupHeadsCollectorManager<T>

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

All Implemented Interfaces:
  `CollectorManager<AllGroupHeadsCollector<T>,AllGroupHeadsCollectorManager.GroupHeadsResult>`

public class AllGroupHeadsCollectorManager<T> extends Object implements CollectorManager<AllGroupHeadsCollector<T>,AllGroupHeadsCollectorManager.GroupHeadsResult>
A `CollectorManager` implementation for `AllGroupHeadsCollector` that collects the most relevant document (group head) for each group across multiple segments and merges the per-segment results into a single `AllGroupHeadsCollectorManager.GroupHeadsResult`.

Example usage:

     IndexSearcher searcher = ...; // your IndexSearcher
     AllGroupHeadsCollectorManager<BytesRef> manager =
         new AllGroupHeadsCollectorManager<>(
             () -> new TermGroupSelector("category"), Sort.RELEVANCE);
     GroupHeadsResult result = searcher.search(new MatchAllDocsQuery(), manager);
     Bits groupHeadsBits = result.retrieveGroupHeads(searcher.getIndexReader().maxDoc());

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `AllGroupHeadsCollectorManager.GroupHeadsResult`
  Holds the merged group heads and provides access as an `int[]` or `Bits`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AllGroupHeadsCollectorManager(Supplier<GroupSelector<T>> groupSelectorFactory, Sort sortWithinGroup)`
  Creates a new AllGroupHeadsCollectorManager.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AllGroupHeadsCollector<T>`
  `newCollector()`
  `AllGroupHeadsCollectorManager.GroupHeadsResult`
  `reduce(Collection<AllGroupHeadsCollector<T>> collectors)`

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

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

- ## Constructor Details

  - ### AllGroupHeadsCollectorManager

    public AllGroupHeadsCollectorManager(Supplier<GroupSelector<T>> groupSelectorFactory, Sort sortWithinGroup)
    Creates a new AllGroupHeadsCollectorManager.
    Parameters:
      `groupSelectorFactory` - factory to create group selectors for each collector
      `sortWithinGroup` - the sort to use within each group to determine the group head

- ## Method Details

  - ### newCollector

    public AllGroupHeadsCollector<T> newCollector() throws IOException
    Specified by:
      `newCollector` in interface `CollectorManager<AllGroupHeadsCollector<T>,AllGroupHeadsCollectorManager.GroupHeadsResult>`
    Throws:
      `IOException`

  - ### reduce

    public AllGroupHeadsCollectorManager.GroupHeadsResult reduce(Collection<AllGroupHeadsCollector<T>> collectors)
    Specified by:
      `reduce` in interface `CollectorManager<AllGroupHeadsCollector<T>,AllGroupHeadsCollectorManager.GroupHeadsResult>`