atris commented on code in PR #3418:
URL: https://github.com/apache/solr/pull/3418#discussion_r2195790595


##########
solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java:
##########
@@ -240,7 +241,7 @@ public void changed(SolrPackageLoader.SolrPackage pkg, Ctx 
ctx) {
   }
 
   @SuppressWarnings({"unchecked"})
-  private void initComponents() {
+  private void initComponents(boolean isCombinedQuery) {

Review Comment:
   This is a code smell - initComponents should not be changing behaviour based 
on a flag specific to a component.
   
   This would be solved if we inherited from SearchHandler or dynamically 
injected CombinedQueryComponent using a factory pattern



##########
solr/core/src/java/org/apache/solr/search/combine/ReciprocalRankFusion.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.combine;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TotalHits;
+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.schema.IndexSchema;
+import org.apache.solr.search.DocIterator;
+import org.apache.solr.search.DocList;
+import org.apache.solr.search.DocSlice;
+import org.apache.solr.search.QueryResult;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SortedIntDocSet;
+
+/**
+ * The ReciprocalRankFusion class implements a query and response combiner 
that uses the Reciprocal
+ * Rank Fusion (RRF) algorithm to combine multiple ranked lists into a single 
ranked list.
+ */
+public class ReciprocalRankFusion extends QueryAndResponseCombiner {
+
+  private final int k;
+
+  /**
+   * Constructs a ReciprocalRankFusion instance.
+   *
+   * @param requestParams the SolrParams containing the configuration 
parameters for this combiner.
+   */
+  public ReciprocalRankFusion(SolrParams requestParams) {
+    super(requestParams);
+    this.k =
+        requestParams.getInt(CombinerParams.COMBINER_RRF_K, 
CombinerParams.COMBINER_RRF_K_DEFAULT);
+  }
+
+  @Override
+  public QueryResult combine(List<QueryResult> rankedLists) {
+    List<DocList> docLists = new ArrayList<>(rankedLists.size());
+    for (QueryResult rankedList : rankedLists) {
+      docLists.add(rankedList.getDocList());
+    }
+    QueryResult combinedResult = new QueryResult();
+    combineResults(combinedResult, docLists, false);
+    return combinedResult;
+  }
+
+  @Override
+  public List<ShardDoc> combine(Map<String, List<ShardDoc>> shardDocMap) {
+    HashMap<String, Float> docIdToScore = new HashMap<>();
+    Map<String, ShardDoc> docIdToShardDoc = new HashMap<>();
+    List<ShardDoc> finalShardDocList = new ArrayList<>();
+    for (Map.Entry<String, List<ShardDoc>> shardDocEntry : 
shardDocMap.entrySet()) {
+      List<ShardDoc> shardDocList = shardDocEntry.getValue();
+      int ranking = 1;
+      while (ranking <= shardDocList.size() && ranking <= upTo) {
+        String docId = shardDocList.get(ranking - 1).id.toString();
+        docIdToShardDoc.put(docId, shardDocList.get(ranking - 1));
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    // TODO: Add the remaining items out of upTo limit to the docIdToScore
+    List<Map.Entry<String, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()
+            .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
+            .toList();
+    for (Map.Entry<String, Float> scoredDoc : sortedByScoreDescending) {
+      String docId = scoredDoc.getKey();
+      Float score = scoredDoc.getValue();
+      ShardDoc shardDoc = docIdToShardDoc.get(docId);
+      shardDoc.score = score;
+      finalShardDocList.add(shardDoc);
+    }
+    return finalShardDocList;
+  }
+
+  private Map<Integer, Integer[]> combineResults(
+      QueryResult combinedRankedList,
+      List<DocList> rankedLists,
+      boolean saveRankPositionsForExplain) {
+    Map<Integer, Integer[]> docIdToRanks = null;
+    HashMap<Integer, Float> docIdToScore = new HashMap<>();
+    long totalMatches = 0;
+    for (DocList rankedList : rankedLists) {
+      DocIterator docs = rankedList.iterator();
+      totalMatches = Math.max(totalMatches, rankedList.matches());
+      int ranking = 1;
+      while (docs.hasNext() && ranking <= upTo) {
+        int docId = docs.nextDoc();
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);

Review Comment:
   This is assuming that each query returns upTo number of documents - what 
happens when a query returns lesser number of documents?



##########
solr/core/src/java/org/apache/solr/search/combine/ReciprocalRankFusion.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.combine;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TotalHits;
+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.schema.IndexSchema;
+import org.apache.solr.search.DocIterator;
+import org.apache.solr.search.DocList;
+import org.apache.solr.search.DocSlice;
+import org.apache.solr.search.QueryResult;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SortedIntDocSet;
+
+/**
+ * The ReciprocalRankFusion class implements a query and response combiner 
that uses the Reciprocal
+ * Rank Fusion (RRF) algorithm to combine multiple ranked lists into a single 
ranked list.
+ */
+public class ReciprocalRankFusion extends QueryAndResponseCombiner {
+
+  private final int k;
+
+  /**
+   * Constructs a ReciprocalRankFusion instance.
+   *
+   * @param requestParams the SolrParams containing the configuration 
parameters for this combiner.
+   */
+  public ReciprocalRankFusion(SolrParams requestParams) {
+    super(requestParams);
+    this.k =
+        requestParams.getInt(CombinerParams.COMBINER_RRF_K, 
CombinerParams.COMBINER_RRF_K_DEFAULT);
+  }
+
+  @Override
+  public QueryResult combine(List<QueryResult> rankedLists) {
+    List<DocList> docLists = new ArrayList<>(rankedLists.size());
+    for (QueryResult rankedList : rankedLists) {
+      docLists.add(rankedList.getDocList());
+    }
+    QueryResult combinedResult = new QueryResult();
+    combineResults(combinedResult, docLists, false);
+    return combinedResult;
+  }
+
+  @Override
+  public List<ShardDoc> combine(Map<String, List<ShardDoc>> shardDocMap) {
+    HashMap<String, Float> docIdToScore = new HashMap<>();
+    Map<String, ShardDoc> docIdToShardDoc = new HashMap<>();
+    List<ShardDoc> finalShardDocList = new ArrayList<>();
+    for (Map.Entry<String, List<ShardDoc>> shardDocEntry : 
shardDocMap.entrySet()) {
+      List<ShardDoc> shardDocList = shardDocEntry.getValue();
+      int ranking = 1;
+      while (ranking <= shardDocList.size() && ranking <= upTo) {
+        String docId = shardDocList.get(ranking - 1).id.toString();
+        docIdToShardDoc.put(docId, shardDocList.get(ranking - 1));
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    // TODO: Add the remaining items out of upTo limit to the docIdToScore
+    List<Map.Entry<String, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()
+            .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
+            .toList();
+    for (Map.Entry<String, Float> scoredDoc : sortedByScoreDescending) {
+      String docId = scoredDoc.getKey();
+      Float score = scoredDoc.getValue();
+      ShardDoc shardDoc = docIdToShardDoc.get(docId);
+      shardDoc.score = score;
+      finalShardDocList.add(shardDoc);
+    }
+    return finalShardDocList;
+  }
+
+  private Map<Integer, Integer[]> combineResults(
+      QueryResult combinedRankedList,
+      List<DocList> rankedLists,
+      boolean saveRankPositionsForExplain) {
+    Map<Integer, Integer[]> docIdToRanks = null;
+    HashMap<Integer, Float> docIdToScore = new HashMap<>();
+    long totalMatches = 0;
+    for (DocList rankedList : rankedLists) {
+      DocIterator docs = rankedList.iterator();
+      totalMatches = Math.max(totalMatches, rankedList.matches());
+      int ranking = 1;
+      while (docs.hasNext() && ranking <= upTo) {
+        int docId = docs.nextDoc();
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    List<Map.Entry<Integer, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()
+            .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
+            .toList();
+
+    int combinedResultsLength = docIdToScore.size();
+    int[] combinedResultsDocIds = new int[combinedResultsLength];
+    float[] combinedResultScores = new float[combinedResultsLength];

Review Comment:
   How about early termination for non competitive iterators?



##########
solr/core/src/java/org/apache/solr/search/combine/ReciprocalRankFusion.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.combine;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TotalHits;
+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.schema.IndexSchema;
+import org.apache.solr.search.DocIterator;
+import org.apache.solr.search.DocList;
+import org.apache.solr.search.DocSlice;
+import org.apache.solr.search.QueryResult;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SortedIntDocSet;
+
+/**
+ * The ReciprocalRankFusion class implements a query and response combiner 
that uses the Reciprocal
+ * Rank Fusion (RRF) algorithm to combine multiple ranked lists into a single 
ranked list.
+ */
+public class ReciprocalRankFusion extends QueryAndResponseCombiner {
+
+  private final int k;
+
+  /**
+   * Constructs a ReciprocalRankFusion instance.
+   *
+   * @param requestParams the SolrParams containing the configuration 
parameters for this combiner.
+   */
+  public ReciprocalRankFusion(SolrParams requestParams) {
+    super(requestParams);
+    this.k =
+        requestParams.getInt(CombinerParams.COMBINER_RRF_K, 
CombinerParams.COMBINER_RRF_K_DEFAULT);
+  }
+
+  @Override
+  public QueryResult combine(List<QueryResult> rankedLists) {
+    List<DocList> docLists = new ArrayList<>(rankedLists.size());
+    for (QueryResult rankedList : rankedLists) {
+      docLists.add(rankedList.getDocList());
+    }
+    QueryResult combinedResult = new QueryResult();
+    combineResults(combinedResult, docLists, false);
+    return combinedResult;
+  }
+
+  @Override
+  public List<ShardDoc> combine(Map<String, List<ShardDoc>> shardDocMap) {
+    HashMap<String, Float> docIdToScore = new HashMap<>();
+    Map<String, ShardDoc> docIdToShardDoc = new HashMap<>();
+    List<ShardDoc> finalShardDocList = new ArrayList<>();
+    for (Map.Entry<String, List<ShardDoc>> shardDocEntry : 
shardDocMap.entrySet()) {
+      List<ShardDoc> shardDocList = shardDocEntry.getValue();
+      int ranking = 1;
+      while (ranking <= shardDocList.size() && ranking <= upTo) {
+        String docId = shardDocList.get(ranking - 1).id.toString();
+        docIdToShardDoc.put(docId, shardDocList.get(ranking - 1));
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    // TODO: Add the remaining items out of upTo limit to the docIdToScore
+    List<Map.Entry<String, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()
+            .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
+            .toList();
+    for (Map.Entry<String, Float> scoredDoc : sortedByScoreDescending) {
+      String docId = scoredDoc.getKey();
+      Float score = scoredDoc.getValue();
+      ShardDoc shardDoc = docIdToShardDoc.get(docId);
+      shardDoc.score = score;
+      finalShardDocList.add(shardDoc);
+    }
+    return finalShardDocList;
+  }
+
+  private Map<Integer, Integer[]> combineResults(
+      QueryResult combinedRankedList,
+      List<DocList> rankedLists,
+      boolean saveRankPositionsForExplain) {
+    Map<Integer, Integer[]> docIdToRanks = null;
+    HashMap<Integer, Float> docIdToScore = new HashMap<>();
+    long totalMatches = 0;
+    for (DocList rankedList : rankedLists) {
+      DocIterator docs = rankedList.iterator();
+      totalMatches = Math.max(totalMatches, rankedList.matches());
+      int ranking = 1;
+      while (docs.hasNext() && ranking <= upTo) {
+        int docId = docs.nextDoc();

Review Comment:
   upTo limit is per query, not a global top N. In fusion part, we return all 
unique docs across all subqueries. Where are we enforcing user specified top N 
limit?



##########
solr/core/src/test/org/apache/solr/handler/component/CombinedQueryComponentTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.component;
+
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.CommonParams;
+import org.junit.BeforeClass;
+
+/**
+ * The CombinedQueryComponentTest class is a unit test suite for the 
CombinedQueryComponent in Solr.

Review Comment:
   We should add tests for queries returning no results and score ties



##########
solr/core/src/java/org/apache/solr/search/combine/ReciprocalRankFusion.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.combine;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TotalHits;
+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.schema.IndexSchema;
+import org.apache.solr.search.DocIterator;
+import org.apache.solr.search.DocList;
+import org.apache.solr.search.DocSlice;
+import org.apache.solr.search.QueryResult;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SortedIntDocSet;
+
+/**
+ * The ReciprocalRankFusion class implements a query and response combiner 
that uses the Reciprocal
+ * Rank Fusion (RRF) algorithm to combine multiple ranked lists into a single 
ranked list.
+ */
+public class ReciprocalRankFusion extends QueryAndResponseCombiner {
+
+  private final int k;
+
+  /**
+   * Constructs a ReciprocalRankFusion instance.
+   *
+   * @param requestParams the SolrParams containing the configuration 
parameters for this combiner.
+   */
+  public ReciprocalRankFusion(SolrParams requestParams) {
+    super(requestParams);
+    this.k =
+        requestParams.getInt(CombinerParams.COMBINER_RRF_K, 
CombinerParams.COMBINER_RRF_K_DEFAULT);
+  }
+
+  @Override
+  public QueryResult combine(List<QueryResult> rankedLists) {
+    List<DocList> docLists = new ArrayList<>(rankedLists.size());
+    for (QueryResult rankedList : rankedLists) {
+      docLists.add(rankedList.getDocList());
+    }
+    QueryResult combinedResult = new QueryResult();
+    combineResults(combinedResult, docLists, false);
+    return combinedResult;
+  }
+
+  @Override
+  public List<ShardDoc> combine(Map<String, List<ShardDoc>> shardDocMap) {
+    HashMap<String, Float> docIdToScore = new HashMap<>();
+    Map<String, ShardDoc> docIdToShardDoc = new HashMap<>();
+    List<ShardDoc> finalShardDocList = new ArrayList<>();
+    for (Map.Entry<String, List<ShardDoc>> shardDocEntry : 
shardDocMap.entrySet()) {
+      List<ShardDoc> shardDocList = shardDocEntry.getValue();
+      int ranking = 1;
+      while (ranking <= shardDocList.size() && ranking <= upTo) {
+        String docId = shardDocList.get(ranking - 1).id.toString();
+        docIdToShardDoc.put(docId, shardDocList.get(ranking - 1));
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    // TODO: Add the remaining items out of upTo limit to the docIdToScore
+    List<Map.Entry<String, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()
+            .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
+            .toList();
+    for (Map.Entry<String, Float> scoredDoc : sortedByScoreDescending) {
+      String docId = scoredDoc.getKey();
+      Float score = scoredDoc.getValue();
+      ShardDoc shardDoc = docIdToShardDoc.get(docId);
+      shardDoc.score = score;
+      finalShardDocList.add(shardDoc);
+    }
+    return finalShardDocList;
+  }
+
+  private Map<Integer, Integer[]> combineResults(
+      QueryResult combinedRankedList,
+      List<DocList> rankedLists,
+      boolean saveRankPositionsForExplain) {
+    Map<Integer, Integer[]> docIdToRanks = null;
+    HashMap<Integer, Float> docIdToScore = new HashMap<>();
+    long totalMatches = 0;
+    for (DocList rankedList : rankedLists) {
+      DocIterator docs = rankedList.iterator();
+      totalMatches = Math.max(totalMatches, rankedList.matches());
+      int ranking = 1;
+      while (docs.hasNext() && ranking <= upTo) {
+        int docId = docs.nextDoc();
+        float rrfScore = 1f / (k + ranking);
+        docIdToScore.compute(docId, (id, score) -> (score == null) ? rrfScore 
: score + rrfScore);
+        ranking++;
+      }
+    }
+    List<Map.Entry<Integer, Float>> sortedByScoreDescending =
+        docIdToScore.entrySet().stream()

Review Comment:
   This is essentially number of queries * upto. Have we scale tested this?



##########
solr/core/src/test/org/apache/solr/handler/component/CombinedQueryComponentTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.component;
+
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.CommonParams;
+import org.junit.BeforeClass;
+
+/**
+ * The CombinedQueryComponentTest class is a unit test suite for the 
CombinedQueryComponent in Solr.
+ * It verifies the functionality of the component by performing various 
queries and validating the
+ * responses.
+ */
+@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
+public class CombinedQueryComponentTest extends SolrTestCaseJ4 {
+
+  private static final int NUM_DOCS = 10;
+  private static final String vectorField = "vector";
+
+  /**
+   * Sets up the test class by initializing the core and adding test documents 
to the index. This
+   * method prepares the Solr index with a set of documents for subsequent 
test cases.
+   *
+   * @throws Exception if any error occurs during setup, such as 
initialization failures or indexing
+   *     issues.
+   */
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    initCore("solrconfig-combined-query.xml", "schema-vector-catchall.xml");
+    List<SolrInputDocument> docs = new ArrayList<>();
+    for (int i = 1; i <= NUM_DOCS; i++) {
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", Integer.toString(i));
+      doc.addField("text", "test text for doc " + i);
+      doc.addField("title", "title test for doc " + i);
+      docs.add(doc);
+    }
+    // cosine distance vector1= 1.0
+    docs.get(0).addField(vectorField, Arrays.asList(1f, 2f, 3f, 4f));
+    // cosine distance vector1= 0.998
+    docs.get(1).addField(vectorField, Arrays.asList(1.5f, 2.5f, 3.5f, 4.5f));
+    // cosine distance vector1= 0.992
+    docs.get(2).addField(vectorField, Arrays.asList(7.5f, 15.5f, 17.5f, 
22.5f));
+    // cosine distance vector1= 0.999
+    docs.get(3).addField(vectorField, Arrays.asList(1.4f, 2.4f, 3.4f, 4.4f));
+    // cosine distance vector1= 0.862
+    docs.get(4).addField(vectorField, Arrays.asList(30f, 22f, 35f, 20f));
+    // cosine distance vector1= 0.756
+    docs.get(5).addField(vectorField, Arrays.asList(40f, 1f, 1f, 200f));
+    // cosine distance vector1= 0.970
+    docs.get(6).addField(vectorField, Arrays.asList(5f, 10f, 20f, 40f));
+    // cosine distance vector1= 0.515
+    docs.get(7).addField(vectorField, Arrays.asList(120f, 60f, 30f, 15f));

Review Comment:
   Please add test for the REF score calculation explainability



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