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


##########
solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java:
##########
@@ -54,32 +55,91 @@ public int getK() {
     return k;
   }
 
+  /**
+   * Reads the RRF weight for a query from {@code 
combiner.rrf.weight.<queryKey>}, defaulting to
+   * {@link CombinerParams#DEFAULT_COMBINER_RRF_WEIGHT} when absent. Validated 
once up front by
+   * {@link #validateWeights}.
+   */
+  private float getWeight(SolrParams solrParams, String queryKey) {
+    return solrParams.getFloat(
+        CombinerParams.COMBINER_RRF_WEIGHT + "." + queryKey,
+        CombinerParams.DEFAULT_COMBINER_RRF_WEIGHT);
+  }
+
+  /**
+   * Rejects {@code combiner.rrf.weight.<queryKey>} params whose {@code 
<queryKey>} is not one of
+   * the queries being combined, or whose value is not a positive finite 
number.
+   */
+  private void validateWeights(SolrParams solrParams, Set<String> 
knownQueryKeys) {
+    String prefix = CombinerParams.COMBINER_RRF_WEIGHT + ".";
+    for (Map.Entry<String, String[]> entry : solrParams) {
+      String name = entry.getKey();
+      if (!name.startsWith(prefix)) {
+        continue;
+      }
+      String queryKey = name.substring(prefix.length());
+      if (!knownQueryKeys.contains(queryKey)) {
+        throw new SolrException(
+            SolrException.ErrorCode.BAD_REQUEST,
+            "RRF weight for unknown query '"
+                + queryKey
+                + "'; not in combiner.query: "
+                + knownQueryKeys);
+      }
+      String rawWeight = entry.getValue()[0];
+      float weight;
+      try {
+        weight = Float.parseFloat(rawWeight);
+      } catch (NumberFormatException e) {
+        throw badWeightRequest(queryKey, rawWeight);
+      }

Review Comment:
   I agree, that's cleaner. Fixed it in 
[b7252f6](https://github.com/apache/solr/pull/5119/commits/b7252f6f1628fd32c7f1b41052cec6f7050a7ecd)



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