You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gs...@apache.org on 2022/07/19 19:44:26 UTC

[lucene] branch branch_9x updated: Small tweak to IntervalQuery#visit logic (#1007)

This is an automated email from the ASF dual-hosted git repository.

gsmiller pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 24ca7f4a7e1 Small tweak to IntervalQuery#visit logic (#1007)
24ca7f4a7e1 is described below

commit 24ca7f4a7e10bccf8f7d2e83b65caa50d597bdf5
Author: Greg Miller <gs...@gmail.com>
AuthorDate: Tue Jul 19 12:27:41 2022 -0700

    Small tweak to IntervalQuery#visit logic (#1007)
---
 lucene/CHANGES.txt                                 |  3 +++
 .../lucene/document/LatLonPointDistanceQuery.java  | 10 ++------
 .../apache/lucene/document/RangeFieldQuery.java    |  5 +---
 .../org/apache/lucene/document/SpatialQuery.java   | 27 ++++++----------------
 .../lucene/document/XYPointInGeometryQuery.java    |  5 +---
 .../org/apache/lucene/search/PointInSetQuery.java  | 10 ++------
 .../org/apache/lucene/search/PointRangeQuery.java  | 10 ++------
 7 files changed, 18 insertions(+), 52 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f422c5da0d8..55cbb9bfdc8 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -62,6 +62,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);
             }
           }