Module org.apache.lucene.grouping
Class FirstPassGroupingCollector<T>
java.lang.Object
org.apache.lucene.search.SimpleCollector
org.apache.lucene.search.grouping.FirstPassGroupingCollector<T>
- All Implemented Interfaces:
Collector
,LeafCollector
FirstPassGroupingCollector is the first of two passes necessary to collect grouped hits. This
pass gathers the top N sorted groups. Groups are defined by a
GroupSelector
See org.apache.lucene.search.grouping
for more details including a full code example.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FieldComparator<?>[]
private final int
private int
private final HashMap<T,
CollectedSearchGroup<T>> private final GroupSelector<T>
private final LeafFieldComparator[]
private final boolean
protected TreeSet<CollectedSearchGroup<T>>
private final int[]
private int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionFirstPassGroupingCollector
(GroupSelector<T> groupSelector, Sort groupSort, int topNGroups) Create the first pass collector. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
void
collect
(int doc) Called once for every document matching a query, with the unbased document number.protected void
doSetNextReader
(LeafReaderContext readerContext) This method is called before collectingcontext
.getTopGroups
(int groupOffset) Returns top groups, starting from offset.private boolean
isCompetitive
(int doc) Indicates what features are required from the scorer.void
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 Details
-
groupSelector
-
comparators
-
leafComparators
-
reversed
private final int[] reversed -
topNGroups
private final int topNGroups -
needsScores
private final boolean needsScores -
groupMap
-
compIDXEnd
private final int compIDXEnd -
orderedGroups
-
docBase
private int docBase -
spareSlot
private int spareSlot
-
-
Constructor Details
-
FirstPassGroupingCollector
Create the first pass collector.- Parameters:
groupSelector
- a GroupSelector used to defined groupsgroupSort
- TheSort
used 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 Details
-
scoreMode
Description copied from interface:Collector
Indicates what features are required from the scorer. -
getTopGroups
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:
IOException
-
setScorer
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:
IOException
-
isCompetitive
- Throws:
IOException
-
collect
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
StoredFields.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:
IOException
-
buildSortedSet
- Throws:
IOException
-
doSetNextReader
Description copied from class:SimpleCollector
This method is called before collectingcontext
.- Overrides:
doSetNextReader
in classSimpleCollector
- Throws:
IOException
-
getGroupSelector
- Returns:
- the GroupSelector used for this Collector
-