Module org.apache.lucene.grouping
Class AllGroupHeadsCollector<T>
java.lang.Object
org.apache.lucene.search.SimpleCollector
org.apache.lucene.search.grouping.AllGroupHeadsCollector<T>
- All Implemented Interfaces:
Collector,LeafCollector
- Direct Known Subclasses:
AllGroupHeadsCollector.ScoringGroupHeadsCollector,AllGroupHeadsCollector.SortingGroupHeadsCollector
This collector specializes in collecting the most relevant document (group head) for each group
that matches the query.
Clients should create new collectors by calling newCollector(GroupSelector, Sort)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a group head.private static classprivate static classSpecialized implementation for sorting by scoreprivate static classprivate static classGeneral implementation using aFieldComparatorto select the group head -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected LeafReaderContextprivate final GroupSelector<T> protected Map<T, AllGroupHeadsCollector.GroupHead<T>> protected final int[]protected Scorableprotected final Sort -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateAllGroupHeadsCollector(GroupSelector<T> selector, Sort sort) -
Method Summary
Modifier and TypeMethodDescriptionvoidcollect(int doc) Called once for every document matching a query, with the unbased document number.protected voiddoSetNextReader(LeafReaderContext context) This method is called before collectingcontext.protected Collection<? extends AllGroupHeadsCollector.GroupHead<T>> Returns the collected group heads.intstatic <T> AllGroupHeadsCollector<T> newCollector(GroupSelector<T> selector, Sort sort) Create a new AllGroupHeadsCollector based on the type of within-group Sort requiredprotected abstract AllGroupHeadsCollector.GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) Create a new GroupHead for the given group value, initialized with a doc, context and scorerint[]retrieveGroupHeads(int maxDoc) Indicates what features are required from the scorer.voidCalled before successive calls toLeafCollector.collect(int).Methods inherited from class org.apache.lucene.search.SimpleCollector
getLeafCollectorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.search.LeafCollector
collect, competitiveIterator, finish
-
Field Details
-
groupSelector
-
sort
-
reversed
protected final int[] reversed -
compIDXEnd
protected final int compIDXEnd -
heads
-
context
-
scorer
-
-
Constructor Details
-
AllGroupHeadsCollector
-
-
Method Details
-
newCollector
Create a new AllGroupHeadsCollector based on the type of within-group Sort required- Type Parameters:
T- the group value type- Parameters:
selector- a GroupSelector to define the groupssort- the within-group sort to use to choose the group head document
-
retrieveGroupHeads
- Parameters:
maxDoc- The maxDoc of the top levelIndexReader.- Returns:
- a
FixedBitSetcontaining all group heads.
-
retrieveGroupHeads
public int[] retrieveGroupHeads()- Returns:
- an int array containing all group heads. The size of the array is equal to number of collected unique groups.
-
groupHeadsSize
public int groupHeadsSize()- Returns:
- the number of group heads found for a query.
-
getCollectedGroupHeads
Returns the collected group heads. Subsequent calls should return the same group heads.- Returns:
- the collected group heads
-
collect
Description 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
StoredFields.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:
IOException
-
scoreMode
Description copied from interface:CollectorIndicates what features are required from the scorer. -
doSetNextReader
Description copied from class:SimpleCollectorThis method is called before collectingcontext.- Overrides:
doSetNextReaderin classSimpleCollector- Throws:
IOException
-
setScorer
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:
IOException
-
newGroupHead
protected abstract AllGroupHeadsCollector.GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) throws IOException Create a new GroupHead for the given group value, initialized with a doc, context and scorer- Throws:
IOException
-