ercsonusharma commented on code in PR #5119:
URL: https://github.com/apache/solr/pull/5119#discussion_r4366813193
##########
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:
Nit: getWeight (SolrParams.getFloat) already parses the value and turns a
bad number into a 400, so this block can be `float weight =
getWeight(solrParams, queryKey);` followed by the positive/finite check. The
only loss is that the error for unparsable input doesn't name the parameter,
which seems fine.
--
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]