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 TypeMethodDescriptionvoid
collect
(int doc) static SinglePassGroupingCollector<?>
createKeyword
(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, org.apache.lucene.search.FieldDoc after) Creates aSinglePassGroupingCollector
on aSortedDocValues
field.static SinglePassGroupingCollector<?>
createNumeric
(String groupField, MappedFieldType groupFieldType, org.apache.lucene.search.Sort groupSort, int topN, org.apache.lucene.search.FieldDoc after) Creates aSinglePassGroupingCollector
on aNumericDocValues
field.protected void
doSetNextReader
(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.ScoreMode
void
setScorer
(org.apache.lucene.search.Scorable 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
Methods inherited from interface org.apache.lucene.search.Collector
setWeight
Methods inherited from interface org.apache.lucene.search.LeafCollector
competitiveIterator
-
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 aSinglePassGroupingCollector
on aNumericDocValues
field. It accepts alsoSortedNumericDocValues
field but the collect will fail with anIllegalStateException
if a document contains more than one value for the field.- Parameters:
groupField
- The sort field used to group documents.groupFieldType
- TheMappedFieldType
for this sort field.groupSort
- TheSort
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 aSinglePassGroupingCollector
on aSortedDocValues
field. It accepts alsoSortedSetDocValues
field but the collect will fail with anIllegalStateException
if a document contains more than one value for the field.- Parameters:
groupField
- The sort field used to group documents.groupFieldType
- TheMappedFieldType
for this sort field.groupSort
- TheSort
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
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:
setScorer
in interfaceorg.apache.lucene.search.LeafCollector
- Overrides:
setScorer
in classorg.apache.lucene.search.SimpleCollector
- Throws:
IOException
-
collect
- Specified by:
collect
in interfaceorg.apache.lucene.search.LeafCollector
- Specified by:
collect
in classorg.apache.lucene.search.SimpleCollector
- Throws:
IOException
-
doSetNextReader
protected void doSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext) throws IOException - Overrides:
doSetNextReader
in classorg.apache.lucene.search.SimpleCollector
- Throws:
IOException
-
getGroupSelector
- Returns:
- the GroupSelector used for this Collector
-