You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2025/05/09 18:07:18 UTC

(lucene) branch branch_10x updated: fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when … (#14632) (#14636)

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

mkhl 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 8273341b1ac fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when … (#14632) (#14636)
8273341b1ac is described below

commit 8273341b1ace65c10a9aef52a5847357b473a25b
Author: Mikhail Khludnev <mk...@users.noreply.github.com>
AuthorDate: Fri May 9 21:07:14 2025 +0300

    fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when … (#14632) (#14636)
    
    * fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when point occurs in the edge
---
 .../search/SortedNumericDocValuesMultiRangeQuery.java    | 16 ++++++++++++----
 .../sandbox/search/TestSortedDvMultiRangeQuery.java      | 11 +++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/SortedNumericDocValuesMultiRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/SortedNumericDocValuesMultiRangeQuery.java
index 0412e594db7..cc91d1f9a58 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/SortedNumericDocValuesMultiRangeQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/SortedNumericDocValuesMultiRangeQuery.java
@@ -95,7 +95,13 @@ public class SortedNumericDocValuesMultiRangeQuery extends Query {
         new PriorityQueue<>(clauses.size() * 2) {
           @Override
           protected boolean lessThan(Edge a, Edge b) {
-            return a.getValue() - b.getValue() < 0;
+            if (a.getValue() < b.getValue()) {
+              return true;
+            } else if (a.getValue() == b.getValue()) {
+              return a.point; // if a point is in the edge of the range, pass the point first
+            } else {
+              return false;
+            }
           }
         };
     for (DocValuesMultiRangeQuery.LongRange r : clauses) {
@@ -115,7 +121,7 @@ public class SortedNumericDocValuesMultiRangeQuery extends Query {
     for (int i = 0; i < totalEdges; i++) {
       Edge smallest = heap.pop();
       if (depth == 0 && smallest.point) {
-        if (i < totalEdges - 1 && heap.top().point) { // repeating same points
+        if (i < totalEdges - 1) { // the point sits on the edge of the range
           if (smallest.getValue() == heap.top().getValue()) {
             continue;
           }
@@ -131,11 +137,13 @@ public class SortedNumericDocValuesMultiRangeQuery extends Query {
         } else {
           depth--;
           if (depth == 0) {
-            sortedClauses.add(
+            DocValuesMultiRangeQuery.LongRange range =
                 started.range == smallest.range // no overlap case, the most often
                     ? smallest.range
                     : new DocValuesMultiRangeQuery.LongRange(
-                        started.getValue(), smallest.getValue()));
+                        started.getValue(), smallest.getValue());
+            boolean strictlyIncreasing = sortedClauses.add(range);
+            assert strictlyIncreasing;
             started = null;
           }
         }
diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestSortedDvMultiRangeQuery.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestSortedDvMultiRangeQuery.java
index 1cd0e561d75..1546b0d23d0 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestSortedDvMultiRangeQuery.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestSortedDvMultiRangeQuery.java
@@ -226,6 +226,17 @@ public class TestSortedDvMultiRangeQuery extends LuceneTestCase {
       int lower = ends[pos];
       int upper = ends[pos + 1];
       b.add(lower, upper);
+      for (int repeat = 0; repeat < random().nextInt(3); repeat++) {
+        if (rarely()) {
+          b.add(lower, upper); // plain repeat
+        } else {
+          if (random().nextBoolean()) {
+            b.add(lower, lower); // lower point repeat
+          } else {
+            b.add(upper, upper); // upper point repeat
+          }
+        }
+      }
     }
     return b;
   }