Skip to content

Commit 249152f

Browse files
committed
Add pruning support for FirstPassGroupingCollector
1 parent 15ed5d7 commit 249152f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.TreeSet;
2525
import org.apache.lucene.index.LeafReaderContext;
26+
import org.apache.lucene.search.DocIdSetIterator;
2627
import org.apache.lucene.search.FieldComparator;
2728
import org.apache.lucene.search.LeafFieldComparator;
2829
import org.apache.lucene.search.Pruning;
@@ -91,9 +92,16 @@ public FirstPassGroupingCollector(
9192
for (int i = 0; i < sortFields.length; i++) {
9293
final SortField sortField = sortFields[i];
9394

95+
final Pruning pruning;
96+
if (i == 0) {
97+
pruning = compIDXEnd >= 0 ? Pruning.GREATER_THAN : Pruning.GREATER_THAN_OR_EQUAL_TO;
98+
} else {
99+
pruning = Pruning.NONE;
100+
}
101+
94102
// use topNGroups + 1 so we have a spare slot to use for comparing (tracked by
95103
// this.spareSlot):
96-
comparators[i] = sortField.getComparator(topNGroups + 1, Pruning.NONE);
104+
comparators[i] = sortField.getComparator(topNGroups + 1, pruning);
97105
reversed[i] = sortField.getReverse() ? -1 : 1;
98106
}
99107

@@ -238,6 +246,9 @@ private void collectNewGroup(final int doc) throws IOException {
238246
// number of groups; from here on we will drop
239247
// bottom group when we insert new one:
240248
buildSortedSet();
249+
250+
// Allow pruning for compatible leaf comparators.
251+
leafComparators[0].setHitsThresholdReached();
241252
}
242253

243254
} else {
@@ -327,6 +338,11 @@ private void collectExistingGroup(final int doc, final CollectedSearchGroup<T> g
327338
}
328339
}
329340

341+
@Override
342+
public DocIdSetIterator competitiveIterator() throws IOException {
343+
return leafComparators[0].competitiveIterator();
344+
}
345+
330346
private void buildSortedSet() throws IOException {
331347
final Comparator<CollectedSearchGroup<?>> comparator =
332348
new Comparator<>() {

0 commit comments

Comments
 (0)