kkewwei commented on code in PR #16520:
URL: https://github.com/apache/lucene/pull/16520#discussion_r3923825725


##########
lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java:
##########
@@ -1405,6 +1406,72 @@ public void collect(int doc) {}
     dir.close();
   }
 
+  public void testTwoPhaseFilterUsesBitSet() throws IOException {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig());
+    for (int i = 0; i < 10000; i++) {
+      Document doc = new Document();
+      doc.add(new TextField("body", "dense1", Field.Store.NO));
+      doc.add(new TextField("body", "dense2", Field.Store.NO));
+      doc.add(SortedNumericDocValuesField.indexedField("filter", i % 20));
+      w.addDocument(doc);
+    }
+    w.close();
+
+    DirectoryReader reader = DirectoryReader.open(dir);
+    IndexSearcher searcher = new IndexSearcher(reader);
+    searcher.setQueryCache(null);
+
+    BooleanQuery innerOr =
+        new BooleanQuery.Builder()
+            .add(new TermQuery(new Term("body", "dense1")), Occur.SHOULD)
+            .add(new TermQuery(new Term("body", "dense2")), Occur.SHOULD)
+            .build();
+    Query filterQuery = 
SortedNumericDocValuesField.newSlowRangeQuery("filter", 1, 1);
+
+    LeafReaderContext context = reader.leaves().get(0);
+    Weight filterWeight =
+        searcher.createWeight(searcher.rewrite(filterQuery), 
ScoreMode.COMPLETE, 1f);
+    Scorer filterScorer = filterWeight.scorer(context);
+    assertNotNull(filterScorer);
+    assertTrue(TwoPhaseIterator.unwrap(filterScorer.iterator()) instanceof 
DocValuesRangeIterator);
+
+    BooleanQuery outerQuery =
+        new BooleanQuery.Builder().add(innerOr, Occur.MUST).add(filterQuery, 
Occur.FILTER).build();
+
+    Query rewritten = searcher.rewrite(outerQuery);
+    Weight weight = searcher.createWeight(rewritten, ScoreMode.TOP_SCORES, 1f);
+    int[] collectedDocs = {0};
+    for (LeafReaderContext ctx : reader.leaves()) {
+      ScorerSupplier ss = weight.scorerSupplier(ctx);
+      if (ss != null) {
+        BulkScorer bs = ss.bulkScorer();
+        assertTrue(
+            "Expected MaxScoreBulkScorer but got " + 
bs.getClass().getSimpleName(),
+            bs instanceof MaxScoreBulkScorer);
+        bs.score(
+            new LeafCollector() {
+              @Override
+              public void setScorer(Scorable scorer) {}
+
+              @Override
+              public void collect(int doc) {
+                assertEquals(1, doc % 20);
+                collectedDocs[0]++;

Review Comment:
   Thanks for the review. I updated the test following by 
`testDenseScorersUseBitSet`, so it now specifically verifies that 
`intoBitSet()` is called on the TwoPhaseIterator.



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