Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery (#11884)

* Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery
This commit is contained in:
Lu Xugang 2022-11-07 19:09:52 +08:00 committed by GitHub
parent 48aad5090f
commit a8120bcb32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -158,6 +158,8 @@ Optimizations
* GITHUB#11876: Use ByteArrayComparator to speed up PointInSetQuery in single dimension case. * GITHUB#11876: Use ByteArrayComparator to speed up PointInSetQuery in single dimension case.
(Guo Feng) (Guo Feng)
* GITHUB#11884: Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery. (Lu Xugang)
Other Other
--------------------- ---------------------

View File

@ -298,18 +298,12 @@ public class IndexSortSortedNumericDocValuesRangeQuery extends Query {
ArrayUtil.getUnsignedComparator(points.getBytesPerDimension()); ArrayUtil.getUnsignedComparator(points.getBytesPerDimension());
for (int dim = 0; dim < points.getNumDimensions(); dim++) { for (int dim = 0; dim < points.getNumDimensions(); dim++) {
int offset = dim * points.getBytesPerDimension(); int offset = dim * points.getBytesPerDimension();
if (comparator.compare(points.getMinPackedValue(), offset, queryUpperPoint, offset) > 0) { if (comparator.compare(points.getMinPackedValue(), offset, queryLowerPoint, offset) >= 0
return false; && comparator.compare(points.getMaxPackedValue(), offset, queryUpperPoint, offset) <= 0) {
} return true;
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;
} }
} }
return true; return false;
} }
private BoundedDocIdSetIterator getDocIdSetIteratorOrNullFromBkd( private BoundedDocIdSetIterator getDocIdSetIteratorOrNullFromBkd(

View File

@ -688,6 +688,13 @@ public class TestIndexSortSortedNumericDocValuesRangeQuery extends LuceneTestCas
assertEquals(2500, weight.count(context)); 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); fallbackQuery = LongPoint.newRangeQuery(filedName, 2, 3);
query = new IndexSortSortedNumericDocValuesRangeQuery(filedName, 2, 3, fallbackQuery); query = new IndexSortSortedNumericDocValuesRangeQuery(filedName, 2, 3, fallbackQuery);
weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f); weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);