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
public abstract class AllGroupHeadsCollector<T> extends SimpleCollector
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 Classes Modifier and Type Class Description static class
AllGroupHeadsCollector.GroupHead<T>
Represents a group head.private static class
AllGroupHeadsCollector.ScoringGroupHead<T>
private static class
AllGroupHeadsCollector.ScoringGroupHeadsCollector<T>
Specialized implementation for sorting by scoreprivate static class
AllGroupHeadsCollector.SortingGroupHead<T>
private static class
AllGroupHeadsCollector.SortingGroupHeadsCollector<T>
General implementation using aFieldComparator
to select the group head
-
Field Summary
Fields Modifier and Type Field Description protected int
compIDXEnd
protected LeafReaderContext
context
private GroupSelector<T>
groupSelector
protected java.util.Map<T,AllGroupHeadsCollector.GroupHead<T>>
heads
protected int[]
reversed
protected Scorable
scorer
protected Sort
sort
-
Constructor Summary
Constructors Modifier Constructor Description private
AllGroupHeadsCollector(GroupSelector<T> selector, Sort sort)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
collect(int doc)
Called once for every document matching a query, with the unbased document number.protected void
doSetNextReader(LeafReaderContext context)
This method is called before collectingcontext
.protected java.util.Collection<? extends AllGroupHeadsCollector.GroupHead<T>>
getCollectedGroupHeads()
Returns the collected group heads.int
groupHeadsSize()
static <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()
FixedBitSet
retrieveGroupHeads(int maxDoc)
ScoreMode
scoreMode()
Indicates what features are required from the scorer.void
setScorer(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
-
sort
protected final Sort sort
-
reversed
protected final int[] reversed
-
compIDXEnd
protected final int compIDXEnd
-
heads
protected java.util.Map<T,AllGroupHeadsCollector.GroupHead<T>> heads
-
context
protected LeafReaderContext context
-
scorer
protected Scorable scorer
-
-
Constructor Detail
-
AllGroupHeadsCollector
private AllGroupHeadsCollector(GroupSelector<T> selector, Sort sort)
-
-
Method Detail
-
newCollector
public static <T> AllGroupHeadsCollector<T> newCollector(GroupSelector<T> selector, Sort sort)
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
public FixedBitSet retrieveGroupHeads(int maxDoc)
- Parameters:
maxDoc
- The maxDoc of the top levelIndexReader
.- Returns:
- a
FixedBitSet
containing 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
protected java.util.Collection<? extends AllGroupHeadsCollector.GroupHead<T>> getCollectedGroupHeads()
Returns the collected group heads. Subsequent calls should return the same group heads.- Returns:
- the collected group heads
-
collect
public void collect(int doc) throws java.io.IOException
Description copied from interface:LeafCollector
Called 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 currentLeafReaderContext
will be skipped andIndexSearcher
will 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:
collect
in interfaceLeafCollector
- Specified by:
collect
in classSimpleCollector
- Throws:
java.io.IOException
-
scoreMode
public ScoreMode scoreMode()
Description copied from interface:Collector
Indicates what features are required from the scorer.
-
doSetNextReader
protected void doSetNextReader(LeafReaderContext context) throws java.io.IOException
Description copied from class:SimpleCollector
This method is called before collectingcontext
.- Overrides:
doSetNextReader
in classSimpleCollector
- Throws:
java.io.IOException
-
setScorer
public void setScorer(Scorable scorer) throws java.io.IOException
Description copied from interface:LeafCollector
Called 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:
setScorer
in interfaceLeafCollector
- Overrides:
setScorer
in classSimpleCollector
- Throws:
java.io.IOException
-
newGroupHead
protected abstract AllGroupHeadsCollector.GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) throws java.io.IOException
Create a new GroupHead for the given group value, initialized with a doc, context and scorer- Throws:
java.io.IOException
-
-