Class CollapsingTopDocsCollector<T>
java.lang.Object
org.apache.lucene.search.SimpleCollector
org.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
org.apache.lucene.search.grouping.CollapsingTopDocsCollector<T>
- All Implemented Interfaces:
org.apache.lucene.search.Collector
,org.apache.lucene.search.LeafCollector
public final class CollapsingTopDocsCollector<T>
extends org.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
A collector that groups documents based on field values and returns
CollapseTopFieldDocs
output. The collapsing is done in a single pass by selecting only the top sorted document per collapse key.
The value used for the collapse key of each group can be found in CollapseTopFieldDocs.collapseValues
.
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 collapsing since the group sort
is the same as the query sort.-
Field Summary
Fields inherited from class org.apache.lucene.search.grouping.FirstPassGroupingCollector
orderedGroups
-
Method Summary
Modifier and TypeMethodDescriptionvoid
collect(int doc)
static CollapsingTopDocsCollector<?>
createKeyword(String collapseField, MappedFieldType collapseFieldType, org.apache.lucene.search.Sort sort, int topN, org.apache.lucene.search.FieldDoc after)
Create a collapsing top docs collector on aSortedDocValues
field.static CollapsingTopDocsCollector<?>
createNumeric(String collapseField, MappedFieldType collapseFieldType, org.apache.lucene.search.Sort sort, int topN, org.apache.lucene.search.FieldDoc after)
Create a collapsing top docs collector on aNumericDocValues
field.protected void
doSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext)
TransformFirstPassGroupingCollector.getTopGroups(int)
output inCollapseTopFieldDocs
.org.apache.lucene.search.ScoreMode
Methods inherited from class org.apache.lucene.search.grouping.FirstPassGroupingCollector
getGroupSelector, getTopGroups, setScorer
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.LeafCollector
competitiveIterator
-
Field Details
-
collapseField
-
sort
protected final org.apache.lucene.search.Sort sort
-
-
Method Details
-
getTopDocs
TransformFirstPassGroupingCollector.getTopGroups(int)
output inCollapseTopFieldDocs
. The collapsing needs only one pass so we can get the final top docs at the end of the first pass.- Throws:
IOException
-
scoreMode
public org.apache.lucene.search.ScoreMode scoreMode()- Specified by:
scoreMode
in interfaceorg.apache.lucene.search.Collector
- Overrides:
scoreMode
in classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
-
doSetNextReader
protected void doSetNextReader(org.apache.lucene.index.LeafReaderContext readerContext) throws IOException- Overrides:
doSetNextReader
in classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
- Throws:
IOException
-
collect
- Specified by:
collect
in interfaceorg.apache.lucene.search.LeafCollector
- Overrides:
collect
in classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
- Throws:
IOException
-
createNumeric
public static CollapsingTopDocsCollector<?> createNumeric(String collapseField, MappedFieldType collapseFieldType, org.apache.lucene.search.Sort sort, int topN, @Nullable org.apache.lucene.search.FieldDoc after)Create a collapsing top docs collector 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:
collapseField
- The sort field used to group documents.collapseFieldType
- TheMappedFieldType
for this sort field.sort
- TheSort
used to sort the collapsed hits. The collapsing keeps only the top sorted document per collapsed 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 CollapsingTopDocsCollector<?> createKeyword(String collapseField, MappedFieldType collapseFieldType, org.apache.lucene.search.Sort sort, int topN, @Nullable org.apache.lucene.search.FieldDoc after)Create a collapsing top docs collector 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:
collapseField
- The sort field used to group documents.collapseFieldType
- TheMappedFieldType
for this sort field.sort
- TheSort
used to sort the collapsed hits. The collapsing keeps only the top sorted document per collapsed 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.
-