Skip to content

Commit b756024

Browse files
authored
Implement bulk adding methods for dynamic pruning. (#14365)
1 parent fe86094 commit b756024

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

lucene/CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ Optimizations
185185

186186
* GITHUB#14301: Avoid unnecessary evaluations and skipping documents. (hanbj)
187187

188-
# GITHUB#14203: Decode doc ids in BKD leaves with auto-vectorized loops when using DEFAULT_MAX_POINTS_IN_LEAF_NODE. (Guo Feng)
188+
* GITHUB#14203: Decode doc ids in BKD leaves with auto-vectorized loops when using DEFAULT_MAX_POINTS_IN_LEAF_NODE. (Guo Feng)
189+
190+
* GITHUB#14176: Avoid the per-doc virtual call when building competitive iterator for dynamic pruning. (Guo Feng)
189191

190192
# GITHUB#14361: Introduce new encoding of BPV 21 for DocIdsWriter used in BKD Tree. (Aniketh Jain, Guo Feng)
191193

lucene/core/src/java/org/apache/lucene/index/PointValues.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ public interface IntersectVisitor {
291291
/**
292292
* Similar to {@link IntersectVisitor#visit(int)}, but a bulk visit and implementations may have
293293
* their optimizations.
294+
*
295+
* <p>It is guaranteed that the given iterator is not positioned;
294296
*/
295297
default void visit(DocIdSetIterator iterator) throws IOException {
296298
int docID;

lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.lucene.search.Scorer;
3232
import org.apache.lucene.util.DocIdSetBuilder;
3333
import org.apache.lucene.util.FixedBitSet;
34+
import org.apache.lucene.util.IntsRef;
3435

3536
/**
3637
* Abstract numeric comparator for comparing numeric values. This comparator provides a skipping
@@ -251,6 +252,19 @@ public void visit(int docID, byte[] packedValue) {
251252
}
252253
}
253254

255+
@Override
256+
public void visit(DocIdSetIterator iterator) throws IOException {
257+
if (iterator.advance(maxDocVisited + 1) != DocIdSetIterator.NO_MORE_DOCS) {
258+
adder.add(iterator.docID());
259+
adder.add(iterator);
260+
}
261+
}
262+
263+
@Override
264+
public void visit(IntsRef ref) {
265+
adder.add(ref, maxDocVisited + 1);
266+
}
267+
254268
@Override
255269
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
256270
long min = sortableBytesToLong(minPackedValue);

lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public sealed interface BulkAdder permits FixedBitSetAdder, BufferAdder {
4747
void add(IntsRef docs);
4848

4949
void add(DocIdSetIterator iterator) throws IOException;
50+
51+
void add(IntsRef docs, int docLowerBoundInclusive);
5052
}
5153

5254
private record FixedBitSetAdder(FixedBitSet bitSet) implements BulkAdder {
@@ -65,7 +67,18 @@ public void add(IntsRef docs) {
6567

6668
@Override
6769
public void add(DocIdSetIterator iterator) throws IOException {
68-
bitSet.or(iterator);
70+
iterator.nextDoc();
71+
iterator.intoBitSet(DocIdSetIterator.NO_MORE_DOCS, bitSet, 0);
72+
}
73+
74+
@Override
75+
public void add(IntsRef docs, int docLowerBoundInclusive) {
76+
for (int i = docs.offset, to = docs.offset + docs.length; i < to; i++) {
77+
int doc = docs.ints[i];
78+
if (doc >= docLowerBoundInclusive) {
79+
bitSet.set(doc);
80+
}
81+
}
6982
}
7083
}
7184

@@ -104,6 +117,18 @@ public void add(DocIdSetIterator iterator) throws IOException {
104117
add(docID);
105118
}
106119
}
120+
121+
@Override
122+
public void add(IntsRef docs, int docLowerBoundInclusive) {
123+
int index = buffer.length;
124+
for (int i = docs.offset, to = docs.offset + docs.length; i < to; i++) {
125+
int doc = docs.ints[i];
126+
if (doc >= docLowerBoundInclusive) {
127+
buffer.array[index++] = doc;
128+
}
129+
}
130+
buffer.length = index;
131+
}
107132
}
108133

109134
private final int maxDoc;

0 commit comments

Comments
 (0)