Skip to content

Apache Lucene open-source search software

Small tweak to IntervalQuery#visit logic (#1007)

Greg Millera35dee5b27c8
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 57e38d2b1ce..e1c764cf0ad 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -138,6 +138,9 @@ Optimizations
* LUCENE-10657: CopyBytes now saves one memory copy on ByteBuffersDataOutput. (luyuncheng)
+* GITHUB#1007: Optimize IntersectVisitor#visit implementations for certain bulk-add cases.
+ (Greg Miller)
+
Changes in runtime behavior
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
index 4adf7452913..64eed9cbfc3 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
@@ -271,10 +271,7 @@ final class LatLonPointDistanceQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
if (matches(packedValue)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
@@ -311,10 +308,7 @@ final class LatLonPointDistanceQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
if (matches(packedValue) == false) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ visit(iterator);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
index ab83969de6f..9070a82211c 100644
--- a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
@@ -481,10 +481,7 @@ public abstract class RangeFieldQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] leaf) throws IOException {
if (queryType.matches(ranges, leaf, numDims, bytesPerDim)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
index c6170ecad62..e170a6391fe 100644
--- a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
@@ -437,10 +437,7 @@ abstract class SpatialQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] t) throws IOException {
if (leafPredicate.test(t)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
@@ -486,10 +483,7 @@ abstract class SpatialQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] t) throws IOException {
if (leafPredicate.test(t)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ visit(iterator);
}
}
@@ -539,14 +533,10 @@ abstract class SpatialQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] t) throws IOException {
- boolean matches = leafPredicate.test(t);
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- if (matches) {
- visit(docID);
- } else {
- excluded.set(docID);
- }
+ if (leafPredicate.test(t)) {
+ visit(iterator);
+ } else {
+ excluded.or(iterator);
}
}
@@ -653,10 +643,7 @@ abstract class SpatialQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] t) throws IOException {
if (leafPredicate.test(t) == false) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ visit(iterator);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
index 1533463a273..92e85e5505b 100644
--- a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
@@ -104,10 +104,7 @@ final class XYPointInGeometryQuery extends Query {
double x = XYEncodingUtils.decode(packedValue, 0);
double y = XYEncodingUtils.decode(packedValue, Integer.BYTES);
if (tree.contains(x, y)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
index a49072794dd..8719f2f00c7 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -252,10 +252,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
@Override
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
if (matches(packedValue)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
@@ -360,10 +357,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
assert packedValue.length == pointBytes.length;
if (Arrays.equals(packedValue, pointBytes)) {
// The point for this set of docs matches the point we are querying on
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
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 aeb474422a9..81f838c4165 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -195,10 +195,7 @@ public abstract class PointRangeQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
if (matches(packedValue)) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ adder.add(iterator);
}
}
@@ -235,10 +232,7 @@ public abstract class PointRangeQuery extends Query {
@Override
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
if (matches(packedValue) == false) {
- int docID;
- while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- visit(docID);
- }
+ visit(iterator);
}
}