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:
Collector,LeafCollector
public final class CollapsingTopDocsCollector<T> extends FirstPassGroupingCollector<T>
A collector that groups documents based on field values and returnsCollapseTopFieldDocsoutput. 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 inCollapseTopFieldDocs.collapseValues. TODO: If the sort is based on score we should propagate the mininum competitive score whenorderedGroupsis full. This is safe for collapsing since the groupsortis the same as the query sort.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringcollapseFieldprotected Scorablescorerprotected Sortsort-
Fields inherited from class org.apache.lucene.search.grouping.FirstPassGroupingCollector
orderedGroups
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollect(int doc)Called once for every document matching a query, with the unbased document number.static CollapsingTopDocsCollector<?>createKeyword(String collapseField, MappedFieldType collapseFieldType, Sort sort, int topN)Create a collapsing top docs collector on aSortedDocValuesfield.static CollapsingTopDocsCollector<?>createNumeric(String collapseField, MappedFieldType collapseFieldType, Sort sort, int topN)Create a collapsing top docs collector on aNumericDocValuesfield.CollapseTopFieldDocsgetTopDocs()TransformFirstPassGroupingCollector.getTopGroups(int)output inCollapseTopFieldDocs.ScoreModescoreMode()Indicates what features are required from the scorer.voidsetScorer(Scorable scorer)Called before successive calls toLeafCollector.collect(int).-
Methods inherited from class org.apache.lucene.search.grouping.FirstPassGroupingCollector
doSetNextReader, getGroupSelector, getTopGroups
-
Methods inherited from class org.apache.lucene.search.SimpleCollector
getLeafCollector
-
-
-
-
Method Detail
-
getTopDocs
public CollapseTopFieldDocs getTopDocs() throws IOException
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 ScoreMode scoreMode()
Description copied from interface:CollectorIndicates what features are required from the scorer.- Specified by:
scoreModein interfaceCollector- Overrides:
scoreModein classFirstPassGroupingCollector<T>
-
setScorer
public void setScorer(Scorable scorer) throws IOException
Description copied from interface:LeafCollectorCalled before successive calls toLeafCollector.collect(int). Implementations that need the score of the current document (passed-in toLeafCollector.collect(int)), should save the passed-in Scorer and call scorer.score() when needed.- Specified by:
setScorerin interfaceLeafCollector- Overrides:
setScorerin classFirstPassGroupingCollector<T>- Throws:
IOException
-
collect
public void collect(int doc) throws IOExceptionDescription copied from interface:LeafCollectorCalled once for every document matching a query, with the unbased document number.Note: The collection of the current segment can be terminated by throwing a
CollectionTerminatedException. In this case, the last docs of the currentLeafReaderContextwill be skipped andIndexSearcherwill swallow the exception and continue collection with the next leaf.Note: This is called in an inner search loop. For good search performance, implementations of this method should not call
IndexSearcher.doc(int)orIndexReader.document(int)on every hit. Doing so can slow searches by an order of magnitude or more.- Specified by:
collectin interfaceLeafCollector- Overrides:
collectin classFirstPassGroupingCollector<T>- Throws:
IOException
-
createNumeric
public static CollapsingTopDocsCollector<?> createNumeric(String collapseField, MappedFieldType collapseFieldType, Sort sort, int topN)
Create a collapsing top docs collector on aNumericDocValuesfield. It accepts alsoSortedNumericDocValuesfield but the collect will fail with anIllegalStateExceptionif a document contains more than one value for the field.- Parameters:
collapseField- The sort field used to group documents.collapseFieldType- TheMappedFieldTypefor this sort field.sort- TheSortused 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.
-
createKeyword
public static CollapsingTopDocsCollector<?> createKeyword(String collapseField, MappedFieldType collapseFieldType, Sort sort, int topN)
Create a collapsing top docs collector on aSortedDocValuesfield. It accepts alsoSortedSetDocValuesfield but the collect will fail with anIllegalStateExceptionif a document contains more than one value for the field.- Parameters:
collapseField- The sort field used to group documents.collapseFieldType- TheMappedFieldTypefor this sort field.sort- TheSortused 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.
-
-