jpountz commented on code in PR #14827:
URL: https://github.com/apache/lucene/pull/14827#discussion_r2180963012


##########
lucene/core/src/test/org/apache/lucene/search/TestScorerUtil.java:
##########
@@ -93,4 +94,20 @@ public void testLikelyImpactsEnum() throws IOException {
       }
     }
   }
+
+  public void testMinRequiredScore() {

Review Comment:
   Can you test many iterations at once? Something like:
   
   ```java
   int iters = atLeast(100);
   for (int iter = 0; iter < iters; ++iter) {
    // your test code
   }
   ```



##########
lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java:
##########
@@ -116,6 +116,25 @@ public int length() {
     }
   }
 
+  /**
+   * Compute a minimum required score, so that (float) 
MathUtil.sumUpperBound(minRequiredScore +
+   * maxRemainingScore, numScorers) <= minCompetitiveScore. The computed value 
may not be the
+   * greatest value that meets this condition, which means that we may fail to 
filter out some docs.
+   * However, this doesn't hurt correctness, it just means that these docs 
will be filtered out
+   * later, and the extra work required to compute an optimal value would 
unlikely result in a
+   * speedup.
+   */
+  static double minRequiredScore(
+      double maxRemainingScore, float minCompetitiveScore, int numScorers) {
+    double minRequiredScore = minCompetitiveScore - maxRemainingScore;
+    double subtraction = Math.ulp((double) minCompetitiveScore);

Review Comment:
   ```suggestion
       double subtraction = Math.ulp(minCompetitiveScore); // note: we want the 
float ulp, not the double ulp
   ```
   
   Sorry, I realize that the current code was my suggestion, but looking at it 
again, we need to take the float ulp to make sure it converges quickly.



##########
lucene/core/src/test/org/apache/lucene/search/TestScorerUtil.java:
##########
@@ -93,4 +94,20 @@ public void testLikelyImpactsEnum() throws IOException {
       }
     }
   }
+
+  public void testMinRequiredScore() {
+    double maxRemainingScore = random().nextDouble();
+    float minCompetitiveScore = random().nextFloat();
+    int numScorers = random().nextInt(1, 10);
+
+    double minRequiredScore =
+        ScorerUtil.minRequiredScore(maxRemainingScore, minCompetitiveScore, 
numScorers);

Review Comment:
   I wonder if there's a way to track the number of iterations and fail the 
test if it took more than X (e.g. 10) iterations to converge.



##########
lucene/core/src/test/org/apache/lucene/search/TestScorerUtil.java:
##########
@@ -93,4 +94,20 @@ public void testLikelyImpactsEnum() throws IOException {
       }
     }
   }
+
+  public void testMinRequiredScore() {
+    double maxRemainingScore = random().nextDouble();
+    float minCompetitiveScore = random().nextFloat();
+    int numScorers = random().nextInt(1, 10);

Review Comment:
   Let's test with high numbers of clauses too?
   
   ```suggestion
       int numScorers = random().nextInt(1, 1000);
   ```



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