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 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcollapseFieldprotected org.apache.lucene.search.Scorerscorerprotected org.apache.lucene.search.Sortsort
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollect(int doc)static CollapsingTopDocsCollector<?>createKeyword(java.lang.String collapseField, org.apache.lucene.search.Sort sort, int topN, boolean trackMaxScore)Create a collapsing top docs collector on aSortedDocValuesfield.static CollapsingTopDocsCollector<?>createNumeric(java.lang.String collapseField, org.apache.lucene.search.Sort sort, int topN, boolean trackMaxScore)Create a collapsing top docs collector on aNumericDocValuesfield.CollapseTopFieldDocsgetTopDocs()TransformFirstPassGroupingCollector.getTopGroups(int, boolean)output inCollapseTopFieldDocs.booleanneedsScores()voidsetScorer(org.apache.lucene.search.Scorer scorer)-
Methods inherited from class org.apache.lucene.search.grouping.FirstPassGroupingCollector
doSetNextReader, getGroupSelector, getTopGroups
-
-
-
-
Method Detail
-
getTopDocs
public CollapseTopFieldDocs getTopDocs() throws java.io.IOException
TransformFirstPassGroupingCollector.getTopGroups(int, boolean)output inCollapseTopFieldDocs. The collapsing needs only one pass so we can get the final top docs at the end of the first pass.- Throws:
java.io.IOException
-
needsScores
public boolean needsScores()
- Specified by:
needsScoresin interfaceorg.apache.lucene.search.Collector- Overrides:
needsScoresin classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
-
setScorer
public void setScorer(org.apache.lucene.search.Scorer scorer) throws java.io.IOException- Specified by:
setScorerin interfaceorg.apache.lucene.search.LeafCollector- Overrides:
setScorerin classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>- Throws:
java.io.IOException
-
collect
public void collect(int doc) throws java.io.IOException- Specified by:
collectin interfaceorg.apache.lucene.search.LeafCollector- Overrides:
collectin classorg.apache.lucene.search.grouping.FirstPassGroupingCollector<T>- Throws:
java.io.IOException
-
createNumeric
public static CollapsingTopDocsCollector<?> createNumeric(java.lang.String collapseField, org.apache.lucene.search.Sort sort, int topN, boolean trackMaxScore)
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.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(java.lang.String collapseField, org.apache.lucene.search.Sort sort, int topN, boolean trackMaxScore)
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.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.
-
-