costin commented on code in PR #16160:
URL: https://github.com/apache/lucene/pull/16160#discussion_r3416815057


##########
lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIteratorIntoBitSet.java:
##########
@@ -598,4 +599,108 @@ public void testRangeIntoBitSetMatchesPerDocEvaluation() 
throws Exception {
       }
     }
   }
+
+  public void testRangeIntoBitSetMatchesPerDocEvaluationWithDeltaEncoding() 
throws Exception {
+    long delta = 1_000_000L;
+    long[] values = rangeValues(DOC_COUNT, doc -> delta + doc);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "delta-only encoded range must match decoded evaluation",
+        values,
+        delta + 127,
+        delta + 4097);
+  }
+
+  public void testRangeIntoBitSetMatchesPerDocEvaluationWithGcdEncoding() 
throws Exception {
+    long[] values = rangeValues(DOC_COUNT, doc -> doc * 1_000L);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "gcd encoded range must match decoded evaluation", values, 123_456L, 
4_567_890L);
+  }
+
+  public void 
testRangeIntoBitSetMatchesPerDocEvaluationWithGcdAndDeltaEncoding() throws 
Exception {
+    long delta = 1_000_000L;
+    long[] values = rangeValues(DOC_COUNT, doc -> delta + doc * 100L);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "gcd+delta encoded range must match decoded evaluation",
+        values,
+        delta + 123,
+        delta + 456_789);
+  }
+
+  public void 
testRangeIntoBitSetMatchesPerDocEvaluationWhenGcdRangeFallsBetweenValues()
+      throws Exception {
+    long[] values = rangeValues(DOC_COUNT, doc -> 10L + doc * 5L);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "gcd encoded gap range must match no docs", values, 11, 14);
+  }
+
+  public void testRangeIntoBitSetMatchesPerDocEvaluationWithOverflowFallback() 
throws Exception {
+    long delta = 1_000_000L;
+    long[] values = rangeValues(DOC_COUNT, doc -> delta + doc);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "overflowing transformed lower bound must fall back to decoded 
evaluation",
+        values,
+        Long.MIN_VALUE,
+        delta + 127);
+  }
+
+  public void 
testRangeIntoBitSetMatchesPerDocEvaluationWithFullGcdDeltaRange() throws 
Exception {
+    long delta = 1_000_000L;
+    long[] values = rangeValues(DOC_COUNT, doc -> delta + doc * 100L);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "full gcd+delta encoded range must match all docs",
+        values,
+        delta,
+        delta + (DOC_COUNT - 1L) * 100L);
+  }
+
+  public void 
testRangeIntoBitSetMatchesPerDocEvaluationWithSingleGcdDeltaValue() throws 
Exception {
+    long delta = 1_000_000L;
+    long value = delta + 123L * 100L;
+    long[] values = rangeValues(DOC_COUNT, doc -> delta + doc * 100L);
+    assertRangeIntoBitSetMatchesPerDocEvaluation(
+        "single gcd+delta encoded value range must match one doc", values, 
value, value);
+  }
+
+  private static long[] rangeValues(int numDocs, LongUnaryOperator 
valueFunction) {
+    long[] values = new long[numDocs];
+    for (int i = 0; i < numDocs; i++) {
+      values[i] = valueFunction.applyAsLong(i);
+    }
+    return values;
+  }
+
+  private void assertRangeIntoBitSetMatchesPerDocEvaluation(
+      String message, long[] values, long rangeMin, long rangeMax) throws 
Exception {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig().setCodec(new 
Lucene104Codec());
+      try (IndexWriter w = new IndexWriter(dir, iwc)) {
+        for (long value : values) {
+          Document doc = new Document();
+          doc.add(NumericDocValuesField.indexedField("val", value));
+          w.addDocument(doc);
+        }
+        w.forceMerge(1);
+      }
+
+      try (DirectoryReader reader = DirectoryReader.open(dir)) {
+        LeafReaderContext ctx = reader.leaves().get(0);
+        FixedBitSet expected = new FixedBitSet(values.length);
+        NumericDocValues slowDv = ctx.reader().getNumericDocValues("val");
+        for (int d = 0; d < values.length; d++) {
+          if (slowDv.advanceExact(d)) {
+            long value = slowDv.longValue();
+            if (value >= rangeMin && value <= rangeMax) {
+              expected.set(d);
+            }
+          }
+        }
+
+        FixedBitSet actual = new FixedBitSet(values.length);
+        NumericDocValues fastDv = ctx.reader().getNumericDocValues("val");
+        fastDv.rangeIntoBitSet(0, values.length, rangeMin, rangeMax, actual, 
0);
+
+        assertEquals(message, expected, actual);
+      }
+    }
+  }

Review Comment:
   Added testRangeIntoBitSetMatchesPerDocEvaluationWithRangeBelowStoredValues 
(and a symmetric WithRangeAboveStoredValues) for that.



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