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


##########
solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java:
##########
@@ -1162,14 +1164,29 @@ protected void mergeIds(ResponseBuilder rb, 
ShardRequest sreq) {
     // the docs offset -> queuesize
     int resultSize = queue.size() - ss.getOffset();
     resultSize = Math.max(0, resultSize); // there may not be any docs in range
-
     Map<Object, ShardDoc> resultIds = new HashMap<>();
-    for (int i = resultSize - 1; i >= 0; i--) {
-      ShardDoc shardDoc = queue.pop();
-      shardDoc.positionInResponse = i;
-      // Need the toString() for correlation with other lists that must
-      // be strings (like keys in highlighting, explain, etc)
-      resultIds.put(shardDoc.id.toString(), shardDoc);
+
+    if (rb instanceof CombinedQueryResponseBuilder) {
+      QueryAndResponseCombiner combinerStrategy =
+          QueryAndResponseCombiner.getImplementation(rb.req.getParams());
+      List<ShardDoc> combinedShardDocs = combinerStrategy.combine(shardDocMap);
+      maxScore = 0.0f;
+      for (int i = 0; i < resultSize; i++) {
+        ShardDoc shardDoc = combinedShardDocs.get(i);
+        shardDoc.positionInResponse = i;
+        maxScore = Math.max(maxScore, shardDoc.score);
+        // Need the toString() for correlation with other lists that must
+        // be strings (like keys in highlighting, explain, etc)
+        resultIds.put(shardDoc.id.toString(), shardDoc);
+      }
+    } else {
+      for (int i = resultSize - 1; i >= 0; i--) {
+        ShardDoc shardDoc = queue.pop();
+        shardDoc.positionInResponse = i;
+        // Need the toString() for correlation with other lists that must
+        // be strings (like keys in highlighting, explain, etc)
+        resultIds.put(shardDoc.id.toString(), shardDoc);
+      }

Review Comment:
   Wondering if factoring out a protected `QueryComponent` method for this 
block (and the `resultSize` and `resultIds` above) would allow the 
`CombinedQueryComponent` to override the method, avoiding the need for `rb 
instanceof CombinedQueryResponseBuilder` above e.g.
   ```suggestion
         Map<Object, ShardDoc>  resultIds = createResultIds(queue, 
ss.getOffset());
   ```



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to