gsmiller commented on code in PR #12003:
URL: https://github.com/apache/lucene/pull/12003#discussion_r1044937729


##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java:
##########
@@ -406,117 +406,121 @@ public Relation compare(byte[] minPackedValue, byte[] 
maxPackedValue) {
 
   private boolean matchNone(PointValues points, byte[] queryLowerPoint, byte[] 
queryUpperPoint)
       throws IOException {
+    assert points.getNumDimensions() == 1;
     final ByteArrayComparator comparator =
         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
-          || comparator.compare(points.getMaxPackedValue(), offset, 
queryLowerPoint, offset) < 0) {
-        return true;
-      }
-    }
-    return false;
+    return comparator.compare(points.getMinPackedValue(), 0, queryUpperPoint, 
0) > 0
+        || comparator.compare(points.getMaxPackedValue(), 0, queryLowerPoint, 
0) < 0;
   }
 
   private boolean matchAll(PointValues points, byte[] queryLowerPoint, byte[] 
queryUpperPoint)
       throws IOException {
+    assert points.getNumDimensions() == 1;
     final ByteArrayComparator comparator =
         ArrayUtil.getUnsignedComparator(points.getBytesPerDimension());
-    for (int dim = 0; dim < points.getNumDimensions(); dim++) {
-      int offset = dim * points.getBytesPerDimension();
-      if (comparator.compare(points.getMinPackedValue(), offset, 
queryLowerPoint, offset) >= 0
-          && comparator.compare(points.getMaxPackedValue(), offset, 
queryUpperPoint, offset) <= 0) {
-        return true;
-      }
-    }
-    return false;
+    return comparator.compare(points.getMinPackedValue(), 0, queryLowerPoint, 
0) >= 0
+        && comparator.compare(points.getMaxPackedValue(), 0, queryUpperPoint, 
0) <= 0;
   }
 
-  private BoundedDocIdSetIterator getDocIdSetIteratorOrNullFromBkd(
+  private DocIdSetIterator getDocIdSetIteratorOrNullFromBkd(
       LeafReaderContext context, DocIdSetIterator delegate) throws IOException 
{
     Sort indexSort = context.reader().getMetaData().getSort();
-    if (indexSort != null
-        && indexSort.getSort().length > 0
-        && indexSort.getSort()[0].getField().equals(field)) {
-      final boolean reverse = indexSort.getSort()[0].getReverse();
-      PointValues points = context.reader().getPointValues(field);
-      if (points == null) {
-        return null;
-      }
+    if (indexSort == null
+        || indexSort.getSort().length == 0
+        || indexSort.getSort()[0].getField().equals(field) == false) {
+      return null;
+    }
 
-      if (points.getNumDimensions() != 1) {
-        return null;
-      }
+    final boolean reverse = indexSort.getSort()[0].getReverse();
 
-      if (points.getBytesPerDimension() != Long.BYTES
-          && points.getBytesPerDimension() != Integer.BYTES) {
-        return null;
-      }
+    PointValues points = context.reader().getPointValues(field);
+    if (points == null) {
+      return null;
+    }
 
-      if (points.size() != points.getDocCount()) {
-        return null;
-      }
+    if (points.getNumDimensions() != 1) {
+      return null;
+    }
+
+    if (points.getBytesPerDimension() != Long.BYTES
+        && points.getBytesPerDimension() != Integer.BYTES) {
+      return null;
+    }
 
-      byte[] queryLowerPoint;
-      byte[] queryUpperPoint;
-      if (points.getBytesPerDimension() == Integer.BYTES) {
-        queryLowerPoint = IntPoint.pack((int) lowerValue).bytes;
-        queryUpperPoint = IntPoint.pack((int) upperValue).bytes;
+    if (points.size() != points.getDocCount()) {
+      return null;
+    }
+
+    assert lowerValue <= upperValue;
+    byte[] queryLowerPoint;
+    byte[] queryUpperPoint;
+    if (points.getBytesPerDimension() == Integer.BYTES) {
+      queryLowerPoint = IntPoint.pack((int) lowerValue).bytes;
+      queryUpperPoint = IntPoint.pack((int) upperValue).bytes;
+    } else {
+      queryLowerPoint = LongPoint.pack(lowerValue).bytes;
+      queryUpperPoint = LongPoint.pack(upperValue).bytes;
+    }
+    if (matchNone(points, queryLowerPoint, queryUpperPoint)) {
+      return DocIdSetIterator.empty();
+    }
+    if (matchAll(points, queryLowerPoint, queryUpperPoint)) {
+      int maxDoc = context.reader().maxDoc();
+      if (points.getDocCount() == maxDoc) {
+        return delegate;

Review Comment:
   Good suggestion! That should be functionally correct (and more efficient 
than relying on delegate here). Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to