You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "jpountz (via GitHub)" <gi...@apache.org> on 2023/10/17 07:52:01 UTC

Re: [PR] Scorer should sum up scores into a double [lucene]

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


##########
lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java:
##########
@@ -266,7 +265,7 @@ public float score() throws IOException {
       score += optScorer.score();
     }
 
-    return score;
+    return (float) score;

Review Comment:
   Actually your change doesn't help here since this sums up two floats at most and summing up two floats is already guaranteed to be as accurate as a float can be. Let's revert changes on this file?



##########
lucene/core/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java:
##########
@@ -504,9 +504,9 @@ public TFIDFScorer(float boost, Explanation idf, float[] normTable) {
 
     @Override
     public float score(float freq, long norm) {
-      final float raw = tf(freq) * queryWeight; // compute tf(f)*weight
+      final double raw = tf(freq) * queryWeight; // compute tf(f)*weight
       float normValue = normTable[(int) (norm & 0xFF)];
-      return raw * normValue; // normalize for field
+      return (float) (raw * normValue); // normalize for field

Review Comment:
   Likewise here, float multiplication is already guaranteed to give a result that is as accurate as a float can give.
   
   One could argue that we could get more accuracy by casting into a double before multiplying in the first multiplication, ie. `final double raw = (double) tf(freq) * queryWeight;`. But I don't think we should do it as similarity scores are a bit fuzzy by nature, and this would very unlikely improve ranking effectiveness. The main reason why we cast into doubles when summing up scores in not really to get better accuracy, but more so that the other in which clauses are evaluated doesn't have an impact on the final score.
   
   Let's revert changes on this file as well?



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