shubhamvishu commented on code in PR #12857:
URL: https://github.com/apache/lucene/pull/12857#discussion_r1410612335


##########
lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java:
##########
@@ -118,13 +118,38 @@ private TopDocs getLeafResults(LeafReaderContext ctx, 
Weight filterWeight) throw
       return NO_RESULTS;
     }
 
-    BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, maxDoc);
-    int cost = acceptDocs.cardinality();
+    DocIdSetIterator iterator = scorer.iterator();
+    BitSet bitSet =
+        iterator instanceof BitSetIterator
+            ? ((BitSetIterator) iterator).getBitSet()
+            : BitSet.of(iterator, maxDoc);
+    Bits acceptDocs =
+        new Bits() {
+          @Override
+          public boolean get(int index) {
+            return liveDocs != null ? liveDocs.get(index) & bitSet.get(index) 
: bitSet.get(index);
+          }
+
+          @Override
+          public int length() {
+            return bitSet.cardinality();
+          }
+        };

Review Comment:
   Why are we creating this when we could  directly do `int cost = 
bitSet.cardinality();`



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to