michaeljmarshall commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r4138760041


##########
lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java:
##########
@@ -262,13 +264,57 @@ assert assertItersOnSameDoc()
       return doNext(lead.advance(target));
     }
 
+    @Override
+    public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws 
IOException {
+      assert offset <= docID() : "offset=" + offset + " docID()=" + docID() + 
" upTo=" + upTo;
+      int doc = docID();
+      if (doc >= upTo) {
+        return;
+      }
+
+      // Bulk masking has fixed per-window cost; sparse leads are cheaper to 
advance per doc.
+      if (lead.cost() < bitSet.length()) {
+        super.intoBitSet(upTo, bitSet, offset);
+        return;
+      }
+
+      int bulkUpTo = Math.min(upTo, minLength);
+      long destinationEnd = (long) offset + bitSet.length();
+      if (destinationEnd < bulkUpTo) {
+        bulkUpTo = (int) destinationEnd;
+      }
+
+      if (doc < bulkUpTo) {
+        if (scratch == null || scratch.length() != bitSet.length()) {
+          scratch = new FixedBitSet(bitSet.length());
+        } else {
+          scratch.clear();
+        }
+
+        lead.intoBitSet(bulkUpTo, scratch, offset);
+        for (BitSet bitSetMask : bitSets) {
+          bitSetMask.applyMask(scratch, offset);
+        }
+        bitSet.or(scratch);
+
+        doNext(lead.docID());
+      }
+
+      if (docID() < upTo) {
+        super.intoBitSet(upTo, bitSet, offset);
+      }
+    }
+
     private int doNext(int doc) throws IOException {
       advanceLead:
       for (; ; doc = lead.nextDoc()) {
         if (doc >= minLength) {
           if (doc != NO_MORE_DOCS) {
             lead.advance(NO_MORE_DOCS);
           }
+          for (BitSetIterator iterator : bitSetIterators) {
+            iterator.setDocId(NO_MORE_DOCS);
+          }

Review Comment:
   Not sure if it is worth back porting to older branches, but it is something 
that we've hit 
https://github.com/elastic/elasticsearch/pull/160540#pullrequestreview-5358742778.
 However, it would seem that this is only reachable when the iterator has 
returned `NO_MORE_DOCS`, and the javadoc specifically says:
   
   ```
    * This abstract class defines methods to iterate over a set of 
non-decreasing doc ids. Note that
    * this class assumes it iterates on doc Ids, and therefore {@link 
#NO_MORE_DOCS} is set to {@value
    * #NO_MORE_DOCS} in order to be used as a sentinel object. Implementations 
of this class are
    * expected to consider {@link Integer#MAX_VALUE} as an invalid value.
    ```



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