costin commented on code in PR #16220:
URL: https://github.com/apache/lucene/pull/16220#discussion_r3453257619


##########
lucene/core/src/java/org/apache/lucene/search/WANDScorer.java:
##########
@@ -566,17 +566,20 @@ public float score() throws IOException {
 
   @Override
   public int advanceShallow(int target) throws IOException {
-    // Propagate to improve score bounds
+    // Propagate to sub-scorers. Scorers past target constrain the boundary to 
docID - 1.
+    int newUpTo = DocIdSetIterator.NO_MORE_DOCS;
     for (Scorer scorer : allScorers) {
-      if (scorer.docID() < target) {
-        scorer.advanceShallow(target);
+      if (scorer.docID() <= target) {
+        newUpTo = Math.min(newUpTo, scorer.advanceShallow(target));
+      } else if (scorer.docID() != DocIdSetIterator.NO_MORE_DOCS) {
+        newUpTo = Math.min(newUpTo, scorer.docID() - 1);

Review Comment:
   Consider  `return (target <= upTo) ? Math.min(upTo, newUpTo) : newUpTo;`
   
   Otherwise the early return discards the freshly computed newUpTo, which 
could be tighter than upTo.
   Always returning the previous upTo is safe (advanceShallow contract allows 
over-approximation), but it means the parent gets a looser bound than necessary 
hence the suggested conditional.
    



##########
lucene/core/src/java/org/apache/lucene/search/WANDScorer.java:
##########
@@ -566,17 +566,20 @@ public float score() throws IOException {
 
   @Override
   public int advanceShallow(int target) throws IOException {
-    // Propagate to improve score bounds
+    // Propagate to sub-scorers. Scorers past target constrain the boundary to 
docID - 1.
+    int newUpTo = DocIdSetIterator.NO_MORE_DOCS;
     for (Scorer scorer : allScorers) {
-      if (scorer.docID() < target) {
-        scorer.advanceShallow(target);
+      if (scorer.docID() <= target) {

Review Comment:
   Nit: the old code used < target (skip propagation when already at target), 
this uses <= target. The <= is correct here since you need the return value 
from advanceShallow even when docID() == target, but worth a one-line comment 
explaining the change from < to <=  (vs a typo).



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