jpountz commented on code in PR #12194: URL: https://github.com/apache/lucene/pull/12194#discussion_r1129172572
########## lucene/core/src/java/org/apache/lucene/search/DocIdSetIterator.java: ########## @@ -211,4 +216,22 @@ protected final int slowAdvance(int target) throws IOException { * may be a rough heuristic, hardcoded value, or otherwise completely inaccurate. */ public abstract long cost(); + + /** + * Returns the next doc ID that may not be a match. Note that this API will essentially provide + * the following two guarantees: Review Comment: I would also add that it's illegal to call this method once the iterator is exhausted. ########## lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java: ########## @@ -142,15 +142,43 @@ public TwoPhaseIterator twoPhaseIterator() { final float matchCost = matchCost(reqApproximation, reqTwoPhaseIterator, exclApproximation, exclTwoPhaseIterator); + final DocIdSetIterator skippingReqApproximation = + new DocIdSetIterator() { + @Override + public int docID() { + return reqApproximation.docID(); + } + + @Override + public int nextDoc() throws IOException { + int exclNonMatchingDoc = exclApproximation.peekNextNonMatchingDocID(); + if (exclApproximation.docID() < docID() && docID() < exclNonMatchingDoc) { + return reqApproximation.advance(exclNonMatchingDoc); + } else { + return reqApproximation.nextDoc(); + } + } + + @Override + public int advance(int target) throws IOException { + return reqApproximation.advance(target); Review Comment: In general we like `advance(docID()+1)` to not perform too differently from `nextDoc()`, maybe we should have the peekNextNonMatchingDocID logic here too? -- 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