gf2121 commented on code in PR #14523:
URL: https://github.com/apache/lucene/pull/14523#discussion_r2051668144


##########
lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java:
##########
@@ -524,17 +524,21 @@ public int advance(int target) throws IOException {
 
     @Override
     public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws 
IOException {
+      upTo = Math.min(upTo, maxDoc);
       if (upTo <= doc) {
         return;
       }
       // Optimize the case when intersecting the competitive iterator is 
expensive, which is when it
       // hasn't nailed down a disjunction of competitive terms yet.
       if (disjunction == null) {
         if (docsWithField != null) {
+          // we need to be absolutely sure that the iterator is at least at 
offset
+          if (docsWithField.docID() < offset) {

Review Comment:
   > The contract from DocIdSetIterator#intoBitSet requires starting from the 
current doc rather than the first doc on or after offset, so it would be more 
correct to advance to doc here. 
   
   So things might got broken when current doc is after the first doc like
   
   ```
   CompetitiveIterator competitiveIterator = CompetitiveIterator.of(1, 2, 3, 4);
   competitiveIterator.advance(2); // advance current doc to 2
   competitiveIterator.update(0, 2000); // update to doc value
   final int offset = 1;
   if (competitiveIterator.docID() < offset) {
     competitiveIterator.advance(offset);
   }
   competitiveIterator.intoBitSet(upTo, bitset, offset); // we should start 
from 2 instead of 1.
   ```
   
   ? Nice catch! 



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