jpountz commented on a change in pull request #1952:
URL: https://github.com/apache/lucene-solr/pull/1952#discussion_r500574341



##########
File path: lucene/core/src/java/org/apache/lucene/search/Weight.java
##########
@@ -266,4 +274,45 @@ static void scoreAll(LeafCollector collector, 
DocIdSetIterator iterator, TwoPhas
     }
   }
 
+  /**
+   * Wraps an internal docIdSetIterator for it to start with docID = -1
+   */
+  protected static class RangeDISIWrapper extends DocIdSetIterator {
+    private final DocIdSetIterator in;
+    private final int min;
+    private final int max;
+    private int docID = -1;
+
+    public RangeDISIWrapper(DocIdSetIterator in, int max) {
+      this.in = in;
+      this.min = in.docID();
+      this.max = max;
+    }
+
+    @Override
+    public int docID() {
+      return docID;
+    }
+
+    @Override
+    public int nextDoc() throws IOException {
+      return advance(docID + 1);
+    }
+
+    @Override
+    public int advance(int target) throws IOException {
+      target = Math.max(min, target);
+      if (target >= max) {
+        return docID = NO_MORE_DOCS;
+      }
+      return docID = in.advance(target);

Review comment:
       it just occurred to me that this implementation is not correct in the 
case that the minimum bound of the range of doc IDs to score is less than the 
current doc ID of the scorer, have you seen any failures with your change? I 
wonder that we would need to do
   ```
   if (target >= scorer.docID()) { return scorer.docID(); }
   ```
   but we should create a test that fails without this




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

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