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


##########
lucene/core/src/java/org/apache/lucene/search/BatchDocValuesRangeIterator.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.io.IOException;
+import org.apache.lucene.index.DocValuesSkipper;
+import org.apache.lucene.index.NumericDocValues;
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A {@link DocIdSetIterator} for numeric doc values range queries that 
batch-evaluates values for
+ * MAYBE blocks. Instead of checking one doc at a time through a {@link
+ * org.apache.lucene.search.TwoPhaseIterator}, this iterator reads values in a 
tight loop and sets
+ * bits directly in a {@link FixedBitSet}, enabling the {@link 
DenseConjunctionBulkScorer} to use
+ * the faster bitset intersection path.
+ *
+ * <p>This is used for dense single-valued numeric fields with a skip index.
+ */
+public final class BatchDocValuesRangeIterator extends DocIdSetIterator {
+
+  private final SkipBlockRangeIterator blockIterator;
+  private final NumericDocValues values;
+  private final long minValue;
+  private final long maxValue;
+  private int doc = -1;
+
+  public BatchDocValuesRangeIterator(
+      NumericDocValues values, DocValuesSkipper skipper, long minValue, long 
maxValue) {
+    this.blockIterator = new SkipBlockRangeIterator(skipper, minValue, 
maxValue);
+    this.values = values;
+    this.minValue = minValue;
+    this.maxValue = maxValue;
+  }
+
+  @Override
+  public int docID() {
+    return doc;
+  }
+
+  @Override
+  public int nextDoc() throws IOException {
+    return advance(doc + 1);
+  }
+
+  @Override
+  public int advance(int target) throws IOException {
+    // Use the block iterator to skip NO blocks
+    int blockDoc = blockIterator.docID();
+    if (blockDoc < target) {
+      blockDoc = blockIterator.advance(target);
+    }
+    if (blockDoc == NO_MORE_DOCS) {
+      return doc = NO_MORE_DOCS;
+    }
+
+    // For YES blocks, all docs match — find the first doc with a value
+    if (blockIterator.getMatch() == SkipBlockRangeIterator.Match.YES) {
+      return doc = blockDoc;
+    }
+

Review Comment:
   Makes sense. I have now removed the redundant YES_IF_PRESENT code, and 
merged it with MAYBE one. Please take a look.



-- 
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