From a8120bcb32d03de949d5871cadff08b3fb270a8e Mon Sep 17 00:00:00 2001 From: Lu Xugang Date: Mon, 7 Nov 2022 19:09:52 +0800 Subject: [PATCH] Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery (#11884) * Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery --- lucene/CHANGES.txt | 2 ++ .../IndexSortSortedNumericDocValuesRangeQuery.java | 14 ++++---------- ...tIndexSortSortedNumericDocValuesRangeQuery.java | 7 +++++++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index bfd79ec9b79..aba34b0fc9e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -158,6 +158,8 @@ Optimizations * GITHUB#11876: Use ByteArrayComparator to speed up PointInSetQuery in single dimension case. (Guo Feng) +* GITHUB#11884: Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery. (Lu Xugang) + Other --------------------- diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java index 723803e6d08..af9cb4ed979 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java @@ -298,18 +298,12 @@ public class IndexSortSortedNumericDocValuesRangeQuery extends Query { ArrayUtil.getUnsignedComparator(points.getBytesPerDimension()); for (int dim = 0; dim < points.getNumDimensions(); dim++) { int offset = dim * points.getBytesPerDimension(); - if (comparator.compare(points.getMinPackedValue(), offset, queryUpperPoint, offset) > 0) { - return false; - } - if (comparator.compare(points.getMaxPackedValue(), offset, queryLowerPoint, offset) < 0) { - return false; - } - if (comparator.compare(points.getMinPackedValue(), offset, queryLowerPoint, offset) < 0 - || comparator.compare(points.getMaxPackedValue(), offset, queryUpperPoint, offset) > 0) { - return false; + if (comparator.compare(points.getMinPackedValue(), offset, queryLowerPoint, offset) >= 0 + && comparator.compare(points.getMaxPackedValue(), offset, queryUpperPoint, offset) <= 0) { + return true; } } - return true; + return false; } private BoundedDocIdSetIterator getDocIdSetIteratorOrNullFromBkd( diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java index b8aa0b5a65d..d68b38839d1 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java @@ -688,6 +688,13 @@ public class TestIndexSortSortedNumericDocValuesRangeQuery extends LuceneTestCas assertEquals(2500, weight.count(context)); } + fallbackQuery = LongPoint.newRangeQuery(filedName, 5, 9); + query = new IndexSortSortedNumericDocValuesRangeQuery(filedName, 2, 10, fallbackQuery); + weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f); + for (LeafReaderContext context : searcher.getLeafContexts()) { + assertEquals(2500, weight.count(context)); + } + fallbackQuery = LongPoint.newRangeQuery(filedName, 2, 3); query = new IndexSortSortedNumericDocValuesRangeQuery(filedName, 2, 3, fallbackQuery); weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);