punAhuja commented on code in PR #5119:
URL: https://github.com/apache/solr/pull/5119#discussion_r4489528191


##########
solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java:
##########
@@ -127,26 +187,37 @@ public SimpleOrderedMap<Explanation> getExplanations(
       List<ShardDoc> combinedQueriesDocs,
       SolrParams solrParams) {
     int kVal = solrParams.getInt(CombinerParams.COMBINER_RRF_K, this.k);
+    float[] weights = new float[queryKeys.length];
+    for (int i = 0; i < queryKeys.length; i++) {
+      weights[i] = getWeight(solrParams, queryKeys[i]);
+    }
     SimpleOrderedMap<Explanation> docIdsExplanations = new 
SimpleOrderedMap<>();
-    Map<String, Integer[]> docIdToRanks = getRanks(queriesDocMap.values(), 
combinedQueriesDocs);
+    Map<String, Integer[]> docIdToRanks = getRanks(queryKeys, queriesDocMap, 
combinedQueriesDocs);
     for (ShardDoc shardDoc : combinedQueriesDocs) {
       String docId = shardDoc.id.toString();
       Integer[] rankPerQuery = docIdToRanks.get(docId);
       Explanation fullDocIdExplanation =
           Explanation.match(
-              shardDoc.score, getReciprocalRankFusionExplain(queryKeys, 
rankPerQuery, kVal));
+              shardDoc.score,
+              getReciprocalRankFusionExplain(queryKeys, rankPerQuery, kVal, 
weights));
       docIdsExplanations.add(docId, fullDocIdExplanation);
     }
     return docIdsExplanations;
   }
 
   private String getReciprocalRankFusionExplain(
-      String[] queryKeys, Integer[] rankPerQuery, int kVal) {
+      String[] queryKeys, Integer[] rankPerQuery, int kVal, float[] weights) {
     StringBuilder reciprocalRankFusionExplain = new StringBuilder();
     StringJoiner scoreComponents = new StringJoiner(" + ");
-    for (Integer rank : rankPerQuery) {
+    for (int i = 0; i < queryKeys.length; i++) {
+      Integer rank = rankPerQuery[i];
       if (rank != null) {
-        scoreComponents.add("1/(" + kVal + "+" + rank + ")");
+        float weight = weights[i];
+        if (weight == CombinerParams.DEFAULT_COMBINER_RRF_WEIGHT) {
+          scoreComponents.add("1/(" + kVal + "+" + rank + ")");
+        } else {

Review Comment:
   This keeps the explain text as 1/(k+rank) when the weight is 1, same as 
unweighted RRF today. Without the check, the float prints as 1.0/(k+rank). The 
score is unchanged. I can remove the check if you prefer.



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