Class FirstPassGroupingCollector<T>
- java.lang.Object
-
- org.apache.lucene.search.SimpleCollector
-
- org.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
-
- All Implemented Interfaces:
Collector,LeafCollector
public class FirstPassGroupingCollector<T> extends SimpleCollector
FirstPassGroupingCollector is the first of two passes necessary to collect grouped hits. This pass gathers the top N sorted groups. Groups are defined by aGroupSelectorSee
org.apache.lucene.search.groupingfor more details including a full code example.
-
-
Field Summary
Fields Modifier and Type Field Description private FieldComparator<?>[]comparatorsprivate intcompIDXEndprivate intdocBaseprivate java.util.HashMap<T,CollectedSearchGroup<T>>groupMapprivate GroupSelector<T>groupSelectorprivate LeafFieldComparator[]leafComparatorsprivate booleanneedsScoresprotected java.util.TreeSet<CollectedSearchGroup<T>>orderedGroupsprivate int[]reversedprivate intspareSlotprivate inttopNGroups
-
Constructor Summary
Constructors Constructor Description FirstPassGroupingCollector(GroupSelector<T> groupSelector, Sort groupSort, int topNGroups)Create the first pass collector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildSortedSet()voidcollect(int doc)Called once for every document matching a query, with the unbased document number.protected voiddoSetNextReader(LeafReaderContext readerContext)This method is called before collectingcontext.GroupSelector<T>getGroupSelector()java.util.Collection<SearchGroup<T>>getTopGroups(int groupOffset)Returns top groups, starting from offset.private booleanisCompetitive(int doc)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.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 Detail
-
groupSelector
private final GroupSelector<T> groupSelector
-
comparators
private final FieldComparator<?>[] comparators
-
leafComparators
private final LeafFieldComparator[] leafComparators
-
reversed
private final int[] reversed
-
topNGroups
private final int topNGroups
-
needsScores
private final boolean needsScores
-
groupMap
private final java.util.HashMap<T,CollectedSearchGroup<T>> groupMap
-
compIDXEnd
private final int compIDXEnd
-
orderedGroups
protected java.util.TreeSet<CollectedSearchGroup<T>> orderedGroups
-
docBase
private int docBase
-
spareSlot
private int spareSlot
-
-
Constructor Detail
-
FirstPassGroupingCollector
public FirstPassGroupingCollector(GroupSelector<T> groupSelector, Sort groupSort, int topNGroups)
Create the first pass collector.- Parameters:
groupSelector- a GroupSelector used to defined groupsgroupSort- TheSortused to sort the groups. The top sorted document within each group according to groupSort, determines how that group sorts against other groups. This must be non-null, ie, if you want to groupSort by relevance use Sort.RELEVANCE.topNGroups- How many top groups to keep.
-
-
Method Detail
-
scoreMode
public ScoreMode scoreMode()
Description copied from interface:CollectorIndicates what features are required from the scorer.
-
getTopGroups
public java.util.Collection<SearchGroup<T>> getTopGroups(int groupOffset) throws java.io.IOException
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:
java.io.IOException
-
setScorer
public void setScorer(Scorable scorer) throws java.io.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 classSimpleCollector- Throws:
java.io.IOException
-
isCompetitive
private boolean isCompetitive(int doc) throws java.io.IOException- Throws:
java.io.IOException
-
collect
public void collect(int doc) throws java.io.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- Specified by:
collectin classSimpleCollector- Throws:
java.io.IOException
-
buildSortedSet
private void buildSortedSet() throws java.io.IOException- Throws:
java.io.IOException
-
doSetNextReader
protected void doSetNextReader(LeafReaderContext readerContext) throws java.io.IOException
Description copied from class:SimpleCollectorThis method is called before collectingcontext.- Overrides:
doSetNextReaderin classSimpleCollector- Throws:
java.io.IOException
-
getGroupSelector
public GroupSelector<T> getGroupSelector()
- Returns:
- the GroupSelector used for this Collector
-
-