sgup432 commented on code in PR #15954:
URL: https://github.com/apache/lucene/pull/15954#discussion_r3089110382


##########
lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java:
##########
@@ -136,16 +136,100 @@ public ScorerSupplier scorerSupplier(LeafReaderContext 
context) throws IOExcepti
         SortedNumericDocValues values = 
DocValues.getSortedNumeric(context.reader(), field);
         final NumericDocValues singleton = DocValues.unwrapSingleton(values);
         final DocValuesSkipper skipper = 
context.reader().getDocValuesSkipper(field);
-        TwoPhaseIterator iterator;
-        if (singleton != null) {
-          if (skipper != null) {
-            final DocIdSetIterator psIterator =
-                getDocIdSetIteratorOrNullForPrimarySort(context.reader(), 
singleton, skipper);
-            if (psIterator != null) {
-              return ConstantScoreScorerSupplier.fromIterator(
-                  psIterator, score(), scoreMode, maxDoc);
-            }
+
+        if (singleton != null && skipper != null) {
+          final DocIdSetIterator psIterator =
+              getDocIdSetIteratorOrNullForPrimarySort(context.reader(), 
singleton, skipper);
+          if (psIterator != null) {
+            return ConstantScoreScorerSupplier.fromIterator(psIterator, 
score(), scoreMode, maxDoc);
           }
+        }
+
+        TwoPhaseIterator iterator;
+        if (skipper != null) {
+          // Use SkipBlockRangeIterator as the approximation: block-level skip
+          // filtering with no DV decoding. This exposes block skips to
+          // ConjunctionDISI so that when one field's block is NO, other fields
+          // never decode DV data for that block.
+          final SkipBlockRangeIterator skipApprox =
+              new SkipBlockRangeIterator(skipper, lowerValue, upperValue);
+          iterator =
+              new TwoPhaseIterator(skipApprox) {
+                private int cachedBlockEnd = -1;
+                private int cachedClassification = BLOCK_MAYBE;
+
+                @Override
+                public boolean matches() throws IOException {
+                  int blockMatch = classifyBlockCached();
+                  if (blockMatch == BLOCK_YES) {
+                    return true;
+                  }
+                  if (blockMatch == BLOCK_IF_DOC_HAS_VALUE) {
+                    if (singleton != null) {
+                      return singleton.advanceExact(skipApprox.docID());
+                    } else {
+                      return values.advanceExact(skipApprox.docID());
+                    }
+                  }
+                  // MAYBE — need to decode DV and check the actual value.
+                  if (singleton != null) {
+                    if (singleton.advanceExact(skipApprox.docID())) {
+                      final long value = singleton.longValue();
+                      return value >= lowerValue && value <= upperValue;
+                    }
+                  } else {
+                    if (values.advanceExact(skipApprox.docID())) {
+                      for (int i = 0, cnt = values.docValueCount(); i < cnt; 
++i) {
+                        final long value = values.nextValue();
+                        if (value < lowerValue) {
+                          continue;
+                        }
+                        return value <= upperValue;
+                      }
+                    }
+                  }
+                  return false;
+                }
+
+                @Override
+                public int docIDRunEnd() throws IOException {
+                  if (classifyBlockCached() == BLOCK_YES) {
+                    return skipApprox.docIDRunEnd();

Review Comment:
   Ah yeah good catch. This might return incorrect results if we expand to a 
higher level. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to