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

Package org.apache.lucene.search.grouping

# Class GroupReducer<T,C extends Collector>

java.lang.Object
org.apache.lucene.search.grouping.GroupReducer<T,C>

Type Parameters:
  `T` - the type of the value used for grouping
  `C` - the type of `Collector` used to reduce each group

public abstract class GroupReducer<T,C extends Collector> extends Object
Concrete implementations of this class define what to collect for individual groups during the second-pass of a grouping search.

Each group is assigned a Collector returned by `newCollector()`, and `LeafCollector.collect(int)` is called for each document that is in a group

See Also:
  - `SecondPassGroupingCollector`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GroupReducer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `collect(T value, int doc)`
  Collect a given document into a given group
  `final C`
  `getCollector(T value)`
  Get the Collector for a given group
  `abstract boolean`
  `needsScores()`
  Whether or not this reducer requires collected documents to be scored
  `protected abstract C`
  `newCollector()`
  Creates a new Collector for each group
  `void`
  `setGroups(Collection<SearchGroup<T>> groups)`
  Define which groups should be reduced.
  `final void`
  `setNextReader(LeafReaderContext ctx)`
  Called when the parent `SecondPassGroupingCollector` moves to a new segment
  `final void`
  `setScorer(Scorable scorer)`
  Set the Scorer on all group collectors

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

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

- ## Constructor Details

  - ### GroupReducer

    public GroupReducer()

- ## Method Details

  - ### setGroups

    public void setGroups(Collection<SearchGroup<T>> groups)
    Define which groups should be reduced.

    Called by `SecondPassGroupingCollector`

  - ### needsScores

    public abstract boolean needsScores()
    Whether or not this reducer requires collected documents to be scored

  - ### newCollector

    protected abstract C newCollector()
    Creates a new Collector for each group

  - ### getCollector

    public final C getCollector(T value)
    Get the Collector for a given group

  - ### collect

    public final void collect(T value, int doc) throws IOException
    Collect a given document into a given group
    Throws:
      `IOException` - on error

  - ### setScorer

    public final void setScorer(Scorable scorer) throws IOException
    Set the Scorer on all group collectors
    Throws:
      `IOException`

  - ### setNextReader

    public final void setNextReader(LeafReaderContext ctx) throws IOException
    Called when the parent `SecondPassGroupingCollector` moves to a new segment
    Throws:
      `IOException`