You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2025/03/13 16:39:23 UTC
(lucene) branch branch_10x updated: Improve PointRangeQuery's "inverse" optimization. (#14353)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 000afb40cb8 Improve PointRangeQuery's "inverse" optimization. (#14353)
000afb40cb8 is described below
commit 000afb40cb8b35ea6140c6c122806898fe5465de
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Thu Mar 13 17:35:25 2025 +0100
Improve PointRangeQuery's "inverse" optimization. (#14353)
When a `PointRangeQuery` matches more than 50% of points and the field is dense
and single-valued, it internally computes the set of docs that don't match the
query, which should be faster since more docs match the query than not.
This change improves this optimization to take advantage of the
`FixedBitSet#or(DocIdSetIterator)` optimization (which internally calls
`DocIdSetIterator#intoBitSet`).
---
.../org/apache/lucene/search/PointRangeQuery.java | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
index 23bdaffa10c..fddafdcaef7 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -212,28 +212,28 @@ public abstract class PointRangeQuery extends Query {
};
}
- /** Create a visitor that clears documents that do NOT match the range. */
+ /** Create a visitor that sets documents that do NOT match the range. */
private IntersectVisitor getInverseIntersectVisitor(FixedBitSet result, long[] cost) {
return new IntersectVisitor() {
@Override
public void visit(int docID) {
- result.clear(docID);
- cost[0]--;
+ result.set(docID);
+ cost[0]++;
}
@Override
public void visit(DocIdSetIterator iterator) throws IOException {
- result.andNot(iterator);
- cost[0] = Math.max(0, cost[0] - iterator.cost());
+ result.or(iterator);
+ cost[0] += iterator.cost();
}
@Override
public void visit(IntsRef ref) {
for (int i = ref.offset; i < ref.offset + ref.length; i++) {
- result.clear(ref.ints[i]);
+ result.set(ref.ints[i]);
}
- cost[0] = Math.max(0, cost[0] - ref.length);
+ cost[0] += ref.length;
}
@Override
@@ -358,9 +358,11 @@ public abstract class PointRangeQuery extends Query {
// than half the leaf size then maybe we can make things faster
// by computing the set of documents that do NOT match the range
final FixedBitSet result = new FixedBitSet(reader.maxDoc());
- result.set(0, reader.maxDoc());
- long[] cost = new long[] {reader.maxDoc()};
+ long[] cost = new long[1];
values.intersect(getInverseIntersectVisitor(result, cost));
+ // Flip the bit set and cost
+ result.flip(0, reader.maxDoc());
+ cost[0] = Math.max(0, reader.maxDoc() - cost[0]);
return new BitSetIterator(result, cost[0]);
}