Module org.elasticsearch.server
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 Summary
Modifier and TypeMethodDescriptionvoidcollect(int doc) static SinglePassGroupingCollector<?> createKeyword(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, org.apache.lucene.search.FieldDoc after) Creates aSinglePassGroupingCollectoron aSortedDocValuesfield.static SinglePassGroupingCollector<?> createNumeric(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, org.apache.lucene.search.FieldDoc after) Creates aSinglePassGroupingCollectoron aNumericDocValuesfield.protected voiddoSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext) org.apache.lucene.search.grouping.GroupSelector<T> getTopGroups(int groupOffset) Returns top groups, starting from offset.org.apache.lucene.search.ScoreModevoidsetScorer(org.apache.lucene.search.Scorable scorer) Methods inherited from class org.apache.lucene.search.SimpleCollector
getLeafCollectorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.search.Collector
setWeightMethods inherited from interface org.apache.lucene.search.LeafCollector
collect, competitiveIterator, finish
-
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 aSinglePassGroupingCollectoron aNumericDocValuesfield. It accepts alsoSortedNumericDocValuesfield but the collect will fail with anIllegalStateExceptionif a document contains more than one value for the field.- Parameters:
groupField- The sort field used to group documents.groupFieldType- TheMappedFieldTypefor this sort field.groupSort- TheSortused 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 aSinglePassGroupingCollectoron aSortedDocValuesfield. It accepts alsoSortedSetDocValuesfield but the collect will fail with anIllegalStateExceptionif a document contains more than one value for the field.- Parameters:
groupField- The sort field used to group documents.groupFieldType- TheMappedFieldTypefor this sort field.groupSort- TheSortused 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
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
- Specified by:
setScorerin interfaceorg.apache.lucene.search.LeafCollector- Overrides:
setScorerin classorg.apache.lucene.search.SimpleCollector- Throws:
IOException
-
collect
- Specified by:
collectin interfaceorg.apache.lucene.search.LeafCollector- Specified by:
collectin classorg.apache.lucene.search.SimpleCollector- Throws:
IOException
-
doSetNextReader
protected void doSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext) throws IOException - Overrides:
doSetNextReaderin classorg.apache.lucene.search.SimpleCollector- Throws:
IOException
-
getGroupSelector
- Returns:
- the GroupSelector used for this Collector
-