Skip to content

Apache Lucene open-source search software

Delegate rangeIntoBitSet in SingletonSortedNumericDocValues (#16295)

Costin Leau38c1036880e5
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2a6cf9ecec4..1d1d5a8154a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -325,7 +325,10 @@ Optimizations
Bug Fixes
---------------------
-(No changes)
+
+* GITHUB#16295: SingletonSortedNumericDocValues now delegates rangeIntoBitSet
+ to the wrapped NumericDocValues, enabling optimized range evaluation for
+ single-valued sorted numeric fields. (Costin Leau)
Other
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedNumericDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedNumericDocValues.java
index 10783561819..f2d3062ec5d 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedNumericDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedNumericDocValues.java
@@ -73,6 +73,13 @@ final class SingletonSortedNumericDocValues extends SortedNumericDocValues {
return in.docIDRunEnd();
}
+ @Override
+ public void rangeIntoBitSet(
+ int fromDoc, int toDoc, long minValue, long maxValue, FixedBitSet bitSet, int offset)
+ throws IOException {
+ in.rangeIntoBitSet(fromDoc, toDoc, minValue, maxValue, bitSet, offset);
+ }
+
@Override
public long cost() {
return in.cost();
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIteratorIntoBitSet.java b/lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIteratorIntoBitSet.java
index 00cb26aca1d..379fb7a0fd0 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIteratorIntoBitSet.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIteratorIntoBitSet.java
@@ -16,6 +16,7 @@
*/
package org.apache.lucene.search;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -25,11 +26,13 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValuesSkipper;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
+import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.FixedBitSet;
@@ -818,6 +821,62 @@ public class TestSkipBlockRangeIteratorIntoBitSet extends BaseDocValuesSkipperTe
}
}
+ public void testSingletonDelegatesRangeIntoBitSet() throws Exception {
+ int maxDoc = 100;
+ boolean[] delegated = {false};
+ NumericDocValues spy =
+ new NumericDocValues() {
+ private int doc = -1;
+
+ @Override
+ public long longValue() {
+ return doc;
+ }
+
+ @Override
+ public boolean advanceExact(int target) {
+ doc = target;
+ return true;
+ }
+
+ @Override
+ public int docID() {
+ return doc;
+ }
+
+ @Override
+ public int nextDoc() {
+ return ++doc < maxDoc ? doc : NO_MORE_DOCS;
+ }
+
+ @Override
+ public int advance(int target) {
+ doc = target;
+ return doc < maxDoc ? doc : NO_MORE_DOCS;
+ }
+
+ @Override
+ public long cost() {
+ return maxDoc;
+ }
+
+ @Override
+ public void rangeIntoBitSet(
+ int fromDoc, int toDoc, long minValue, long maxValue, FixedBitSet bitSet, int offset)
+ throws IOException {
+ delegated[0] = true;
+ super.rangeIntoBitSet(fromDoc, toDoc, minValue, maxValue, bitSet, offset);
+ }
+ };
+
+ SortedNumericDocValues singleton = DocValues.singleton(spy);
+ FixedBitSet bitSet = new FixedBitSet(maxDoc);
+ singleton.rangeIntoBitSet(0, maxDoc, 20, 40, bitSet, 0);
+
+ assertTrue("Expected delegation to NumericDocValues.rangeIntoBitSet", delegated[0]);
+ assertTrue("Expected some bits set", bitSet.cardinality() > 0);
+ }
+
private static long[] rangeValues(int numDocs, LongUnaryOperator valueFunction) {
long[] values = new long[numDocs];
for (int i = 0; i < numDocs; i++) {