|
23 | 23 | import java.util.HashMap;
|
24 | 24 | import java.util.TreeSet;
|
25 | 25 | import org.apache.lucene.index.LeafReaderContext;
|
| 26 | +import org.apache.lucene.search.DocIdSetIterator; |
26 | 27 | import org.apache.lucene.search.FieldComparator;
|
27 | 28 | import org.apache.lucene.search.LeafFieldComparator;
|
28 | 29 | import org.apache.lucene.search.Pruning;
|
@@ -91,9 +92,16 @@ public FirstPassGroupingCollector(
|
91 | 92 | for (int i = 0; i < sortFields.length; i++) {
|
92 | 93 | final SortField sortField = sortFields[i];
|
93 | 94 |
|
| 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 | + |
94 | 102 | // use topNGroups + 1 so we have a spare slot to use for comparing (tracked by
|
95 | 103 | // this.spareSlot):
|
96 |
| - comparators[i] = sortField.getComparator(topNGroups + 1, Pruning.NONE); |
| 104 | + comparators[i] = sortField.getComparator(topNGroups + 1, pruning); |
97 | 105 | reversed[i] = sortField.getReverse() ? -1 : 1;
|
98 | 106 | }
|
99 | 107 |
|
@@ -238,6 +246,9 @@ private void collectNewGroup(final int doc) throws IOException {
|
238 | 246 | // number of groups; from here on we will drop
|
239 | 247 | // bottom group when we insert new one:
|
240 | 248 | buildSortedSet();
|
| 249 | + |
| 250 | + // Allow pruning for compatible leaf comparators. |
| 251 | + leafComparators[0].setHitsThresholdReached(); |
241 | 252 | }
|
242 | 253 |
|
243 | 254 | } else {
|
@@ -327,6 +338,11 @@ private void collectExistingGroup(final int doc, final CollectedSearchGroup<T> g
|
327 | 338 | }
|
328 | 339 | }
|
329 | 340 |
|
| 341 | + @Override |
| 342 | + public DocIdSetIterator competitiveIterator() throws IOException { |
| 343 | + return leafComparators[0].competitiveIterator(); |
| 344 | + } |
| 345 | + |
330 | 346 | private void buildSortedSet() throws IOException {
|
331 | 347 | final Comparator<CollectedSearchGroup<?>> comparator =
|
332 | 348 | new Comparator<>() {
|
|
0 commit comments