Class SinglePassGroupingCollector<T>

java.lang.Object
org.apache.lucene.search.SimpleCollector
org.elasticsearch.lucene.grouping.SinglePassGroupingCollector<T>
All Implemented Interfaces:
org.apache.lucene.search.Collector, org.apache.lucene.search.LeafCollector

public class SinglePassGroupingCollector<T> extends org.apache.lucene.search.SimpleCollector
A collector that groups documents based on field values and returns TopFieldGroups output. The grouping is done in a single pass by selecting only the top sorted document per grouping key. The value used for the key of each group can be found in TopFieldGroups.groupValues. This collector optionally supports searching after a previous result through the 'after' parameter. TODO: If the sort is based on score we should propagate the mininum competitive score when orderedGroups is full. This is safe for grouping since the group sort is the same as the query sort.
  • Method Details

    • createNumeric

      public static SinglePassGroupingCollector<?> createNumeric(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, @Nullable org.apache.lucene.search.FieldDoc after)
      Creates a SinglePassGroupingCollector on a NumericDocValues field. It accepts also SortedNumericDocValues field but the collect will fail with an IllegalStateException if a document contains more than one value for the field.
      Parameters:
      groupField - The sort field used to group documents.
      groupFieldType - The MappedFieldType for this sort field.
      groupSort - The Sort used to sort the groups. The grouping keeps only the top sorted document per grouping key. This must be non-null, ie, if you want to groupSort by relevance use Sort.RELEVANCE.
      topN - How many top groups to keep.
      after - The field values to search after. Can be null.
    • createKeyword

      public static SinglePassGroupingCollector<?> createKeyword(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, @Nullable org.apache.lucene.search.FieldDoc after)
      Creates a SinglePassGroupingCollector on a SortedDocValues field. It accepts also SortedSetDocValues field but the collect will fail with an IllegalStateException if a document contains more than one value for the field.
      Parameters:
      groupField - The sort field used to group documents.
      groupFieldType - The MappedFieldType for this sort field.
      groupSort - The Sort used to sort the groups. The grouping keeps only the top sorted document per grouping key. This must be non-null, ie, if you want to groupSort by relevance use Sort.RELEVANCE.
      topN - How many top groups to keep.
      after - The field values to search after. Can be null.
    • scoreMode

      public org.apache.lucene.search.ScoreMode scoreMode()
    • getTopGroups

      public TopFieldGroups getTopGroups(int groupOffset) throws IOException
      Returns top groups, starting from offset. This may return null, if no groups were collected, or if the number of unique groups collected is <= offset.
      Parameters:
      groupOffset - The offset in the collected groups
      Returns:
      top groups, starting from offset
      Throws:
      IOException
    • setScorer

      public void setScorer(org.apache.lucene.search.Scorable scorer) throws IOException
      Specified by:
      setScorer in interface org.apache.lucene.search.LeafCollector
      Overrides:
      setScorer in class org.apache.lucene.search.SimpleCollector
      Throws:
      IOException
    • collect

      public void collect(int doc) throws IOException
      Specified by:
      collect in interface org.apache.lucene.search.LeafCollector
      Specified by:
      collect in class org.apache.lucene.search.SimpleCollector
      Throws:
      IOException
    • doSetNextReader

      protected void doSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext) throws IOException
      Overrides:
      doSetNextReader in class org.apache.lucene.search.SimpleCollector
      Throws:
      IOException
    • getGroupSelector

      public org.apache.lucene.search.grouping.GroupSelector<T> getGroupSelector()
      Returns:
      the GroupSelector used for this Collector