This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit b6de1bcb5a425b804d3bbea16d99de4839241a30
Author: Puneet Ahuja <[email protected]>
AuthorDate: Thu Nov 19 09:30:51 2026 +0530

    SOLR-18542: Add weighted RRF for combined queries (#5119)
    
    Support weighted Reciprocal Rank Fusion in Combined Query via 
combiner.rrf.weight.<queryName>.
    
    branch_9x delta: the weighted-RRF test in 
DistributedCombinedQueryComponentTest is added to testMultipleLexicalQuery and 
uses string concatenation instead of a text block (Java 11).
    
    (cherry picked from commit f2873bb7783d43d636cc4343ac8b7e84d528c493)
    (cherry picked from commit 122317abc5921ed7604a17df3639fc170c2739ff)
---
 .../unreleased/SOLR-18542-added-weighted-rrf.yml   |   8 ++
 .../component/combine/ReciprocalRankFusion.java    | 100 +++++++++++++++----
 .../DistributedCombinedQueryComponentTest.java     |  15 +++
 .../handler/component/MockResponseBuilder.java     |  27 ++---
 .../combine/ReciprocalRankFusionTest.java          | 109 +++++++++++++++++++++
 .../query-guide/pages/json-combined-query-dsl.adoc |  48 +++++++++
 .../apache/solr/common/params/CombinerParams.java  |   3 +
 7 files changed, 280 insertions(+), 30 deletions(-)

diff --git a/changelog/unreleased/SOLR-18542-added-weighted-rrf.yml 
b/changelog/unreleased/SOLR-18542-added-weighted-rrf.yml
new file mode 100644
index 00000000000..37b239076d2
--- /dev/null
+++ b/changelog/unreleased/SOLR-18542-added-weighted-rrf.yml
@@ -0,0 +1,8 @@
+title: Support weighted Reciprocal Rank Fusion in Combined Query via 
combiner.rrf.weight.<queryName>.
+type: added
+authors:
+  - name: Puneet Ahuja
+    nick: punAhuja
+links:
+  - name: SOLR-18542
+    url: https://issues.apache.org/jira/browse/SOLR-18542
diff --git 
a/solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java
 
b/solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java
index 911c009c0d4..08f55295f2c 100644
--- 
a/solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java
+++ 
b/solr/core/src/java/org/apache/solr/handler/component/combine/ReciprocalRankFusion.java
@@ -17,14 +17,15 @@
 package org.apache.solr.handler.component.combine;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringJoiner;
 import java.util.stream.Collectors;
 import org.apache.lucene.search.Explanation;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CombinerParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
@@ -55,32 +56,85 @@ public class ReciprocalRankFusion extends 
QueryAndResponseCombiner {
     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);
+      }
+      float weight = getWeight(solrParams, queryKey);
+      if (!(weight > 0) || !Float.isFinite(weight)) {
+        throw badWeightRequest(queryKey, entry.getValue()[0]);
+      }
+    }
+  }
+
+  private static SolrException badWeightRequest(String queryKey, String 
rawWeight) {
+    return new SolrException(
+        SolrException.ErrorCode.BAD_REQUEST,
+        "RRF weight for query '"
+            + queryKey
+            + "' must be a positive finite number, found "
+            + rawWeight);
+  }
+
   /**
    * Merges per-query ranked results using Reciprocal Rank Fusion (RRF).
    *
    * <p>Each query doc list is assumed to be ordered by descending relevance. 
For a document at rank
-   * r in the list, the contribution is {@code 1 / (k + r)} where {@code k} is 
read from {@link
-   * CombinerParams#COMBINER_RRF_K} or falls back to {@code this.k}. 
Contributions for the same
-   * document ID across multiple queries (if found) are summed, and documents 
are returned sorted by
-   * the fused score (descending).
+   * r in the list, the contribution is {@code weight / (k + r)}, where {@code 
k} is read from
+   * {@link CombinerParams#COMBINER_RRF_K} or falls back to {@code this.k}, 
and {@code weight} is
+   * read from {@code combiner.rrf.weight.<queryKey>} or defaults to {@link
+   * CombinerParams#DEFAULT_COMBINER_RRF_WEIGHT}. Contributions for the same 
document ID across
+   * multiple queries (if found) are summed, and documents are returned sorted 
by the fused score
+   * (descending).
    *
    * @param queriesDocMap per-query ranked results;
-   * @param solrParams parameters; optional {@link 
CombinerParams#COMBINER_RRF_K} overrides k.
+   * @param solrParams parameters; optional {@link 
CombinerParams#COMBINER_RRF_K} overrides k and
+   *     {@code combiner.rrf.weight.<queryKey>} overrides the per-query weight.
    * @return one {@link ShardDoc} per unique document ID, ordered by fused 
score.
    */
   @Override
   public List<ShardDoc> combine(Map<String, List<ShardDoc>> queriesDocMap, 
SolrParams solrParams) {
     int kVal = solrParams.getInt(CombinerParams.COMBINER_RRF_K, this.k);
+    validateWeights(solrParams, queriesDocMap.keySet());
     HashMap<String, Float> docIdToScore = new HashMap<>();
     Map<String, ShardDoc> docIdToShardDoc = new HashMap<>();
     List<ShardDoc> finalShardDocList = new ArrayList<>();
     for (Map.Entry<String, List<ShardDoc>> shardDocEntry : 
queriesDocMap.entrySet()) {
+      String queryKey = shardDocEntry.getKey();
+      float weight = getWeight(solrParams, queryKey);
       List<ShardDoc> shardDocList = shardDocEntry.getValue();
       int ranking = 1;
       while (ranking <= shardDocList.size()) {
         String docId = shardDocList.get(ranking - 1).id.toString();
         docIdToShardDoc.put(docId, shardDocList.get(ranking - 1));
-        float rrfScore = 1f / (kVal + ranking);
+        float rrfScore = weight * (1f / (kVal + ranking));
         docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
         ranking++;
       }
@@ -102,14 +156,20 @@ public class ReciprocalRankFusion extends 
QueryAndResponseCombiner {
   }
 
   private Map<String, Integer[]> getRanks(
-      Collection<List<ShardDoc>> shardDocs, List<ShardDoc> combinedShardDocs) {
-    Map<String, Integer[]> docIdToRanks;
-    docIdToRanks = new HashMap<>();
+      String[] queryKeys,
+      Map<String, List<ShardDoc>> queriesDocMap,
+      List<ShardDoc> combinedShardDocs) {
+    Map<String, Integer[]> docIdToRanks = new HashMap<>();
     for (ShardDoc shardDoc : combinedShardDocs) {
-      docIdToRanks.put(shardDoc.id.toString(), new Integer[shardDocs.size()]);
+      docIdToRanks.put(shardDoc.id.toString(), new Integer[queryKeys.length]);
     }
     int docIdx = 0;
-    for (List<ShardDoc> shardDocList : shardDocs) {
+    for (String queryKey : queryKeys) {
+      List<ShardDoc> shardDocList = queriesDocMap.get(queryKey);
+      if (shardDocList == null) {
+        docIdx++;
+        continue;
+      }
       int rank = 1;
       for (ShardDoc shardDoc : shardDocList) {
         String docId = shardDoc.id.toString();
@@ -128,26 +188,32 @@ public class ReciprocalRankFusion extends 
QueryAndResponseCombiner {
       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 + ")");
+        scoreComponents.add(weights[i] + "/(" + kVal + "+" + rank + ")");
       }
     }
     reciprocalRankFusionExplain.append(scoreComponents);
diff --git 
a/solr/core/src/test/org/apache/solr/handler/component/DistributedCombinedQueryComponentTest.java
 
b/solr/core/src/test/org/apache/solr/handler/component/DistributedCombinedQueryComponentTest.java
index 00570dd5268..d3772b78542 100644
--- 
a/solr/core/src/test/org/apache/solr/handler/component/DistributedCombinedQueryComponentTest.java
+++ 
b/solr/core/src/test/org/apache/solr/handler/component/DistributedCombinedQueryComponentTest.java
@@ -161,6 +161,21 @@ public class DistributedCombinedQueryComponentTest extends 
BaseDistributedSearch
     QueryResponse rsp = query(CommonParams.JSON, jsonQuery, CommonParams.QT, 
"/search");
     assertEquals(5, rsp.getResults().size());
     assertFieldValues(rsp.getResults(), id, "5", "7", "2", "6", "3");
+
+    // Weighted RRF: a higher weight on lexical2 flips the winner from 1 to 3.
+    // Unweighted (k=60): 1=1/61+1/62, 3=1/63+1/61, 2=1/62+1/63  -> order 1, 
3, 2.
+    // lexical1=1, lexical2=3: 3=1/63+3/61, 1=1/61+3/62, 2=1/62+3/63 -> order 
3, 1, 2.
+    String weightedQuery =
+        "{\"queries\":"
+            + "{\"lexical1\":{\"lucene\":{\"query\":\"id:(1^=10 OR 2^=5 OR 
3^=1)\"}},"
+            + "\"lexical2\":{\"lucene\":{\"query\":\"id:(3^=10 OR 1^=5 OR 
2^=1)\"}}},"
+            + "\"limit\":3,"
+            + "\"fields\":[\"id\",\"score\",\"title\"],"
+            + 
"\"params\":{\"combiner\":true,\"combiner.query\":[\"lexical1\",\"lexical2\"],"
+            + 
"\"combiner.rrf.weight.lexical1\":\"1\",\"combiner.rrf.weight.lexical2\":\"3\"}}";
+    rsp = query(CommonParams.JSON, weightedQuery, CommonParams.QT, "/search");
+    assertEquals(3, rsp.getResults().size());
+    assertFieldValues(rsp.getResults(), id, "3", "1", "2");
   }
 
   /**
diff --git 
a/solr/core/src/test/org/apache/solr/handler/component/MockResponseBuilder.java 
b/solr/core/src/test/org/apache/solr/handler/component/MockResponseBuilder.java
index 1a8cca6f835..fa4efdfe57b 100644
--- 
a/solr/core/src/test/org/apache/solr/handler/component/MockResponseBuilder.java
+++ 
b/solr/core/src/test/org/apache/solr/handler/component/MockResponseBuilder.java
@@ -20,8 +20,8 @@ import java.util.ArrayList;
 import java.util.List;
 import org.apache.solr.common.params.CombinerParams;
 import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.ShardParams;
-import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
@@ -36,9 +36,16 @@ import org.mockito.Mockito;
 
 public class MockResponseBuilder extends ResponseBuilder {
 
+  // real params, so every read (get/getBool/getFloat/iterator) behaves like 
production
+  private final ModifiableSolrParams params;
+
   private MockResponseBuilder(
-      SolrQueryRequest request, SolrQueryResponse response, 
List<SearchComponent> components) {
+      SolrQueryRequest request,
+      SolrQueryResponse response,
+      List<SearchComponent> components,
+      ModifiableSolrParams params) {
     super(request, response, components);
+    this.params = params;
   }
 
   public static MockResponseBuilder create() {
@@ -47,7 +54,7 @@ public class MockResponseBuilder extends ResponseBuilder {
     SolrQueryRequest request = Mockito.mock(SolrQueryRequest.class);
     SolrQueryResponse response = Mockito.mock(SolrQueryResponse.class);
     IndexSchema indexSchema = Mockito.mock(IndexSchema.class);
-    SolrParams params = Mockito.mock(SolrParams.class);
+    ModifiableSolrParams params = new ModifiableSolrParams();
 
     // SchemaField must be concrete due to field access
     SchemaField uniqueIdField = new SchemaField("id", new StrField());
@@ -58,13 +65,12 @@ public class MockResponseBuilder extends ResponseBuilder {
     // the mock implementations
     Mockito.when(request.getSchema()).thenReturn(indexSchema);
     Mockito.when(indexSchema.getUniqueKeyField()).thenReturn(uniqueIdField);
-    Mockito.when(params.getBool(ShardParams.SHARDS_INFO)).thenReturn(false);
     Mockito.when(request.getParams()).thenReturn(params);
     Mockito.when(response.getResponseHeader()).thenReturn(responseHeader);
     Mockito.when(response.getReturnFields()).thenCallRealMethod();
 
     List<SearchComponent> components = new ArrayList<>();
-    return new MockResponseBuilder(request, response, components);
+    return new MockResponseBuilder(request, response, components, params);
   }
 
   public MockResponseBuilder withSortSpec(SortSpec sortSpec) {
@@ -73,10 +79,7 @@ public class MockResponseBuilder extends ResponseBuilder {
   }
 
   public MockResponseBuilder withCombinerQueries(String... combinerQueries) {
-    SolrParams params = req.getParams();
-    
Mockito.when(params.getParams(CombinerParams.COMBINER_QUERY)).thenReturn(combinerQueries);
-    Mockito.when(params.get(CombinerParams.COMBINER_ALGORITHM, 
CombinerParams.DEFAULT_COMBINER))
-        .thenReturn(CombinerParams.DEFAULT_COMBINER);
+    params.set(CombinerParams.COMBINER_QUERY, combinerQueries);
     SolrCore core = Mockito.mock(SolrCore.class);
     
Mockito.when(core.getCoreContainer()).thenReturn(Mockito.mock(CoreContainer.class));
     Mockito.when(req.getCore()).thenReturn(core);
@@ -85,10 +88,8 @@ public class MockResponseBuilder extends ResponseBuilder {
   }
 
   public MockResponseBuilder withShardsTolerant() {
-    SolrParams params = req.getParams();
-    Mockito.when(params.get(ShardParams.SHARDS_TOLERANT)).thenReturn("true");
-    Mockito.when(params.getBool(Mockito.eq(CommonParams.PARTIAL_RESULTS), 
Mockito.anyBoolean()))
-        .thenReturn(true);
+    params.set(ShardParams.SHARDS_TOLERANT, "true");
+    params.set(CommonParams.PARTIAL_RESULTS, "true");
     return this;
   }
 }
diff --git 
a/solr/core/src/test/org/apache/solr/handler/component/combine/ReciprocalRankFusionTest.java
 
b/solr/core/src/test/org/apache/solr/handler/component/combine/ReciprocalRankFusionTest.java
index 40185e3f942..cdef944c130 100644
--- 
a/solr/core/src/test/org/apache/solr/handler/component/combine/ReciprocalRankFusionTest.java
+++ 
b/solr/core/src/test/org/apache/solr/handler/component/combine/ReciprocalRankFusionTest.java
@@ -20,13 +20,16 @@ import static 
org.apache.solr.common.params.CombinerParams.RECIPROCAL_RANK_FUSIO
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import org.apache.lucene.search.Explanation;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CombinerParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.handler.component.ShardDoc;
 import org.apache.solr.search.QueryResult;
 import org.junit.BeforeClass;
@@ -89,6 +92,112 @@ public class ReciprocalRankFusionTest extends 
SolrTestCaseJ4 {
     assertEquals("id2", shardDocs.get(0).id);
   }
 
+  /**
+   * Builds a two-list map: lexical=[A,B,C] and vector=[C,A,B], so ranks 
differ across lists and a
+   * weight change can flip the fused order.
+   */
+  private Map<String, List<ShardDoc>> twoListDocMap() {
+    Map<String, List<ShardDoc>> queriesDocMap = new HashMap<>();
+    List<ShardDoc> lexical = new ArrayList<>();
+    for (String id : List.of("A", "B", "C")) {
+      ShardDoc d = new ShardDoc();
+      d.id = id;
+      d.shard = "shard1";
+      lexical.add(d);
+    }
+    List<ShardDoc> vector = new ArrayList<>();
+    for (String id : List.of("C", "A", "B")) {
+      ShardDoc d = new ShardDoc();
+      d.id = id;
+      d.shard = "shard2";
+      vector.add(d);
+    }
+    queriesDocMap.put("lexical", lexical);
+    queriesDocMap.put("vector", vector);
+    return queriesDocMap;
+  }
+
+  /** Without weights the fused order is A, C, B (k=20). */
+  @Test
+  public void testQueryListCombineNoWeights() {
+    SolrParams solrParams = params();
+    List<ShardDoc> shardDocs = reciprocalRankFusion.combine(twoListDocMap(), 
solrParams);
+    assertEquals(3, shardDocs.size());
+    assertEquals("A", shardDocs.get(0).id);
+    assertEquals("C", shardDocs.get(1).id);
+    assertEquals("B", shardDocs.get(2).id);
+  }
+
+  /** A higher vector weight flips the winner from A to C. */
+  @Test
+  public void testQueryListCombineWithWeights() {
+    SolrParams solrParams =
+        params(
+            CombinerParams.COMBINER_RRF_WEIGHT + ".lexical", "1",
+            CombinerParams.COMBINER_RRF_WEIGHT + ".vector", "3");
+    List<ShardDoc> shardDocs = reciprocalRankFusion.combine(twoListDocMap(), 
solrParams);
+    assertEquals(3, shardDocs.size());
+    assertEquals("C", shardDocs.get(0).id);
+    assertEquals("A", shardDocs.get(1).id);
+    assertEquals("B", shardDocs.get(2).id);
+  }
+
+  /** Omitting one weight defaults it to 1, so only the supplied weight biases 
the list. */
+  @Test
+  public void testQueryListCombineOneWeightOmitted() {
+    SolrParams solrParams = params(CombinerParams.COMBINER_RRF_WEIGHT + 
".lexical", "3");
+    List<ShardDoc> shardDocs = reciprocalRankFusion.combine(twoListDocMap(), 
solrParams);
+    assertEquals(3, shardDocs.size());
+    assertEquals("A", shardDocs.get(0).id);
+  }
+
+  /** A weight of 0, infinity, NaN or an unparsable value is rejected with a 
400. */
+  @Test
+  public void testInvalidWeightThrows() {
+    for (String bad : List.of("0", "-0.5", "Infinity", "-Infinity", "NaN", 
"abc")) {
+      SolrParams solrParams = params(CombinerParams.COMBINER_RRF_WEIGHT + 
".lexical", bad);
+      assertThrows(
+          SolrException.class, () -> 
reciprocalRankFusion.combine(twoListDocMap(), solrParams));
+    }
+  }
+
+  /** A weight for a query name not in combiner.query is rejected with a 400. 
*/
+  @Test
+  public void testUnknownWeightNameThrows() {
+    SolrParams solrParams = params(CombinerParams.COMBINER_RRF_WEIGHT + 
".unknown", "2");
+    assertThrows(
+        SolrException.class, () -> 
reciprocalRankFusion.combine(twoListDocMap(), solrParams));
+  }
+
+  /**
+   * The explain string carries the weight and labels each rank with the 
correct query name, even
+   * when the doc-map iteration order is the reverse of {@code combiner.query} 
order.
+   */
+  @Test
+  public void testExplainWithWeights() {
+    // vector is inserted first, so map order is the reverse of the request 
order below.
+    // A HashMap can iterate in request order by chance and hide a rank/label 
mismatch.
+    Map<String, List<ShardDoc>> source = twoListDocMap();
+    Map<String, List<ShardDoc>> queriesDocMap = new LinkedHashMap<>();
+    queriesDocMap.put("vector", source.get("vector"));
+    queriesDocMap.put("lexical", source.get("lexical"));
+    assertEquals(List.of("vector", "lexical"), 
List.copyOf(queriesDocMap.keySet()));
+    SolrParams solrParams =
+        params(
+            CombinerParams.COMBINER_RRF_WEIGHT + ".lexical", "2",
+            CombinerParams.COMBINER_RRF_WEIGHT + ".vector", "1");
+    List<ShardDoc> combined = reciprocalRankFusion.combine(queriesDocMap, 
solrParams);
+    SimpleOrderedMap<Explanation> explanations =
+        reciprocalRankFusion.getExplanations(
+            new String[] {"lexical", "vector"}, queriesDocMap, combined, 
solrParams);
+    Explanation docA = explanations.get("A");
+    // A is rank 1 in lexical (weight 2) and rank 2 in vector (weight 1)
+    assertTrue(docA.getDescription().contains("2.0/(20+1)"));
+    assertTrue(docA.getDescription().contains("1.0/(20+2)"));
+    assertTrue(docA.getDescription().contains("1 for query(lexical)"));
+    assertTrue(docA.getDescription().contains("2 for query(vector)"));
+  }
+
   @Test
   public void testImplementationFactory() {
     Map<String, QueryAndResponseCombiner> combinerMap = new HashMap<>(1);
diff --git 
a/solr/solr-ref-guide/modules/query-guide/pages/json-combined-query-dsl.adoc 
b/solr/solr-ref-guide/modules/query-guide/pages/json-combined-query-dsl.adoc
index 7af12e2681e..0d22ee11ef0 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/json-combined-query-dsl.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/json-combined-query-dsl.adoc
@@ -75,6 +75,11 @@ The query structure is similar to JSON Query DSL except for 
how multiple queries
    Any other algorithm can be configured using 
xref:json-combined-query-dsl.adoc#combiner-algorithm-plugin[plugin].
 `combiner.rrf.k` | Default: `60`::
    The k parameter in the RRF algorithm.
+`combiner.rrf.weight.<queryName>` | Default: `1.0`::
+   A positive multiplier applied to the reciprocal rank contribution of the 
query named `<queryName>` (where `<queryName>` is an entry in `combiner.query`).
+   If omitted, the query's weight is `1.0`, so all queries contribute equally 
by default.
+   Weights are multipliers, not percentages, and need not sum to `1.0`; a 
weight of `2.0` makes a query twice as influential as a weight of `1.0`.
+   Use this to bias the fusion toward one list, for example to keep an exact 
lexical match above a merely similar vector match.
 
 [NOTE]
 ====
@@ -144,6 +149,49 @@ QueryResponse queryResponse = query.process(solrClient, 
COLLECTION_NAME);
 ====
 ======
 
+=== Weighted RRF Example
+
+To bias the fusion toward the lexical query, give it a higher weight than the 
vector query.
+The weight multiplies that query's reciprocal rank contribution; omitting a 
weight leaves it at the default `1.0`.
+
+[tabs#json-query-with-weights]
+======
+curl::
++
+====
+[source,bash]
+----
+curl http://localhost:8983/solr/techproducts/query -d '
+{
+    "queries": {
+        "lexical1": {
+            "lucene": {
+                "query": "name:apache"
+            }
+        },
+        "vector": {
+            "knn": {
+                "f": "vector",
+                "topK" :5,
+                "query": "[0.1,-0.34,0.89,0.02]"
+            }
+        }
+    },
+    "limit": 5,
+    "fields": ["id", "score", "name"],
+    "params": {
+        "combiner": true,
+        "combiner.query": ["lexical1", "vector"],
+        "combiner.algorithm": "rrf",
+        "combiner.rrf.k": "15",
+        "combiner.rrf.weight.lexical1": "2.0",
+        "combiner.rrf.weight.vector": "1.0"
+    }
+}'
+----
+====
+======
+
 == Combiner Algorithm Plugin
 
 As mentioned xref:json-combined-query-dsl.adoc#query-dsl-structure[above], 
custom algorithms can be configured to combine the results across multiple 
queries using a 
https://solr.apache.org/guide/solr/latest/configuration-guide/solr-plugins.html[Solr
 plugin].
diff --git 
a/solr/solrj/src/java/org/apache/solr/common/params/CombinerParams.java 
b/solr/solrj/src/java/org/apache/solr/common/params/CombinerParams.java
index 23d735d595d..4bc6a416613 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/CombinerParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/CombinerParams.java
@@ -29,7 +29,10 @@ public class CombinerParams {
   public static final String COMBINER_QUERY = COMBINER + ".query";
   public static final String RECIPROCAL_RANK_FUSION = "rrf";
   public static final String COMBINER_RRF_K = COMBINER + "." + 
RECIPROCAL_RANK_FUSION + ".k";
+  public static final String COMBINER_RRF_WEIGHT =
+      COMBINER + "." + RECIPROCAL_RANK_FUSION + ".weight";
   public static final String DEFAULT_COMBINER = RECIPROCAL_RANK_FUSION;
   public static final int DEFAULT_COMBINER_RRF_K = 60;
+  public static final float DEFAULT_COMBINER_RRF_WEIGHT = 1f;
   public static final int DEFAULT_MAX_COMBINER_QUERIES = 5;
 }

Reply via email to