You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/03/01 20:31:17 UTC

[GitHub] [lucene] vigyasharma commented on a change in pull request #711: LUCENE-10428: Avoid infinite loop under error conditions.

vigyasharma commented on a change in pull request #711:
URL: https://github.com/apache/lucene/pull/711#discussion_r817117987



##########
File path: lucene/core/src/java/org/apache/lucene/search/MaxScoreSumPropagator.java
##########
@@ -131,22 +131,28 @@ void setMinCompetitiveScore(float minScore) throws IOException {
   /** Return the minimum score that a Scorer must produce in order for a hit to be competitive. */
   private float getMinCompetitiveScore(float minScoreSum, double sumOfOtherMaxScores) {
     assert numClauses > 0;
-    if (minScoreSum <= sumOfOtherMaxScores) {
-      return 0f;
-    }
 
     // We need to find a value 'minScore' so that 'minScore + sumOfOtherMaxScores <= minScoreSum'
     // TODO: is there an efficient way to find the greatest value that meets this requirement?
     float minScore = (float) (minScoreSum - sumOfOtherMaxScores);
-    int iters = 0;
-    while (scoreSumUpperBound(minScore + sumOfOtherMaxScores) > minScoreSum) {
+    for (int iter = 0;
+        minScore > 0 && scoreSumUpperBound(minScore + sumOfOtherMaxScores) > minScoreSum;
+        ++iter) {
       // Important: use ulp of minScoreSum and not minScore to make sure that we
       // converge quickly.
       minScore -= Math.ulp(minScoreSum);
       // this should converge in at most two iterations:
       //  - one because of the subtraction rounding error
       //  - one because of the error introduced by sumUpperBound
-      assert ++iters <= 2 : iters;
+      if (iter > 2) {
+        throw new IllegalStateException(

Review comment:
       Also publish the last computed value of `minScore` here?




-- 
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-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org