org.apache.lucene.search.grouping

## Class AllGroupHeadsCollector<T>

- java.lang.Object
- - org.apache.lucene.search.SimpleCollector
  - - org.apache.lucene.search.grouping.AllGroupHeadsCollector<T>

- All Implemented Interfaces:
    Collector, LeafCollector

      public abstract class AllGroupHeadsCollector<T>
      extends SimpleCollector

  This collector specializes in collecting the most relevant document (group head) for each group that matches the query. Clients should create new collectors by calling `newCollector(GroupSelector, Sort)`
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AllGroupHeadsCollector.GroupHead<T>` Represents a group head.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `compIDXEnd`
    `protected LeafReaderContext` | `context`
    `protected Map<T,AllGroupHeadsCollector.GroupHead<T>>` | `heads`
    `protected int[]` | `reversed`
    `protected Scorer` | `scorer`
    `protected Sort` | `sort`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `collect(int doc)`
    `protected void` | `doSetNextReader(LeafReaderContext context)`
    `protected Collection<? extends AllGroupHeadsCollector.GroupHead<T>>` | `getCollectedGroupHeads()` Returns the collected group heads.
    `int` | `groupHeadsSize()`
    `boolean` | `needsScores()`
    `static <T> AllGroupHeadsCollector<T>` | `newCollector(GroupSelector<T> selector, Sort sort)` Create a new AllGroupHeadsCollector based on the type of within-group Sort required
    `protected abstract AllGroupHeadsCollector.GroupHead<T>` | `newGroupHead(int doc, T value, LeafReaderContext context, Scorer scorer)` Create a new GroupHead for the given group value, initialized with a doc, context and scorer
    `int[]` | `retrieveGroupHeads()`
    `FixedBitSet` | `retrieveGroupHeads(int maxDoc)`
    `void` | `setScorer(Scorer scorer)`

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

- - ### Field Detail

    - #### sort

          protected final Sort sort

    - #### reversed

          protected final int[] reversed

    - #### compIDXEnd

          protected final int compIDXEnd

    - #### heads

          protected Map<T,AllGroupHeadsCollector.GroupHead<T>> heads

    - #### context

          protected LeafReaderContext context

    - #### scorer

          protected Scorer scorer

  - ### Method Detail

    - #### newCollector

          public static <T> AllGroupHeadsCollector<T> newCollector(GroupSelector<T> selector,
                                                                   Sort sort)

      Create a new AllGroupHeadsCollector based on the type of within-group Sort required
      Type Parameters:
        `T` - the group value type
      Parameters:
        `selector` - a GroupSelector to define the groups
        `sort` - the within-group sort to use to choose the group head document

    - #### retrieveGroupHeads

          public FixedBitSet retrieveGroupHeads(int maxDoc)

      Parameters:
        `maxDoc` - The maxDoc of the top level `IndexReader`.
      Returns:
        a `FixedBitSet` containing all group heads.

    - #### retrieveGroupHeads

          public int[] retrieveGroupHeads()

      Returns:
        an int array containing all group heads. The size of the array is equal to number of collected unique groups.

    - #### groupHeadsSize

          public int groupHeadsSize()

      Returns:
        the number of group heads found for a query.

    - #### getCollectedGroupHeads

          protected Collection<? extends AllGroupHeadsCollector.GroupHead<T>> getCollectedGroupHeads()

      Returns the collected group heads. Subsequent calls should return the same group heads.
      Returns:
        the collected group heads

    - #### collect

          public void collect(int doc)
                       throws IOException

      Specified by:
        `collect` in interface `LeafCollector`
      Specified by:
        `collect` in class `SimpleCollector`
      Throws:
        `IOException`

    - #### needsScores

          public boolean needsScores()

    - #### doSetNextReader

          protected void doSetNextReader(LeafReaderContext context)
                                  throws IOException

      Overrides:
        `doSetNextReader` in class `SimpleCollector`
      Throws:
        `IOException`

    - #### setScorer

          public void setScorer(Scorer scorer)
                         throws IOException

      Specified by:
        `setScorer` in interface `LeafCollector`
      Overrides:
        `setScorer` in class `SimpleCollector`
      Throws:
        `IOException`

    - #### newGroupHead

          protected abstract AllGroupHeadsCollector.GroupHead<T> newGroupHead(int doc,
                                                                              T value,
                                                                              LeafReaderContext context,
                                                                              Scorer scorer)
                                                                       throws IOException

      Create a new GroupHead for the given group value, initialized with a doc, context and scorer
      Throws:
        `IOException`

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