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

[lucene] branch main updated: Use ByteArrayComparator for PointInSetQuery#MergePointVisitor (#11876)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 05bd83dfe12 Use ByteArrayComparator for PointInSetQuery#MergePointVisitor (#11876)
05bd83dfe12 is described below

commit 05bd83dfe12463231b53259aff23b685c8574831
Author: gf2121 <52...@users.noreply.github.com>
AuthorDate: Wed Oct 26 13:39:32 2022 +0800

    Use ByteArrayComparator for PointInSetQuery#MergePointVisitor (#11876)
---
 lucene/CHANGES.txt                                        |  3 +++
 .../java/org/apache/lucene/search/PointInSetQuery.java    | 15 +++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 362bddd3ad5..9901dc0087d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -150,6 +150,9 @@ Optimizations
   given field to match a term (rather than all docs in a segment). This is consistent with
   MultiTermQueryConstantScoreWrapper. (Greg Miller)
 
+* GITHUB#11876: Use ByteArrayComparator to speed up PointInSetQuery in single dimension case.
+  (Guo Feng)
+
 Other
 ---------------------
 * LUCENE-10423: Remove usages of System.currentTimeMillis() from tests. (Marios Trivyzas)
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 8719f2f00c7..13533cf25c7 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -214,7 +214,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
     private final DocIdSetBuilder result;
     private TermIterator iterator;
     private BytesRef nextQueryPoint;
-    private final BytesRef scratch = new BytesRef();
+    private final ByteArrayComparator comparator;
     private final PrefixCodedTerms sortedPackedPoints;
     private DocIdSetBuilder.BulkAdder adder;
 
@@ -222,7 +222,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
         throws IOException {
       this.result = result;
       this.sortedPackedPoints = sortedPackedPoints;
-      scratch.length = bytesPerDim;
+      this.comparator = ArrayUtil.getUnsignedComparator(bytesPerDim);
       this.iterator = this.sortedPackedPoints.iterator();
       nextQueryPoint = iterator.next();
     }
@@ -257,9 +257,8 @@ public abstract class PointInSetQuery extends Query implements Accountable {
     }
 
     private boolean matches(byte[] packedValue) {
-      scratch.bytes = packedValue;
       while (nextQueryPoint != null) {
-        int cmp = nextQueryPoint.compareTo(scratch);
+        int cmp = comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, packedValue, 0);
         if (cmp == 0) {
           return true;
         } else if (cmp < 0) {
@@ -276,15 +275,15 @@ public abstract class PointInSetQuery extends Query implements Accountable {
     @Override
     public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
       while (nextQueryPoint != null) {
-        scratch.bytes = minPackedValue;
-        int cmpMin = nextQueryPoint.compareTo(scratch);
+        int cmpMin =
+            comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, minPackedValue, 0);
         if (cmpMin < 0) {
           // query point is before the start of this cell
           nextQueryPoint = iterator.next();
           continue;
         }
-        scratch.bytes = maxPackedValue;
-        int cmpMax = nextQueryPoint.compareTo(scratch);
+        int cmpMax =
+            comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, maxPackedValue, 0);
         if (cmpMax > 0) {
           // query point is after the end of this cell
           return Relation.CELL_OUTSIDE_QUERY;