cpoerschke commented on a change in pull request #300: SOLR-11831: Skip second 
grouping step if group.limit is 1 (aka Las Vegas Patch)
URL: https://github.com/apache/lucene-solr/pull/300#discussion_r276714459
 
 

 ##########
 File path: 
solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SkipSecondStepSearchGroupShardResponseProcessor.java
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * 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.grouping.distributed.responseprocessor;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.TotalHits;
+import org.apache.lucene.search.grouping.GroupDocs;
+import org.apache.lucene.search.grouping.SearchGroup;
+import org.apache.lucene.search.grouping.TopGroups;
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.handler.component.ResponseBuilder;
+import org.apache.solr.handler.component.ShardDoc;
+import org.apache.solr.handler.component.ShardResponse;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.grouping.GroupingSpecification;
+import 
org.apache.solr.search.grouping.distributed.shardresultserializer.SearchGroupsResultTransformer;
+
+public class SkipSecondStepSearchGroupShardResponseProcessor extends 
SearchGroupShardResponseProcessor {
+
+  @Override
+  protected SearchGroupsResultTransformer 
newSearchGroupsResultTransformer(SolrIndexSearcher solrIndexSearcher) {
+    return new 
SearchGroupsResultTransformer.SkipSecondStepSearchResultResultTransformer(solrIndexSearcher);
+  }
+
+  @Override
+  protected SearchGroupsContainer newSearchGroupsContainer(ResponseBuilder rb) 
{
+    return new 
SkipSecondStepSearchGroupsContainer(rb.getGroupingSpec().getFields());
+  }
+
+  protected static class SkipSecondStepSearchGroupsContainer extends 
SearchGroupsContainer {
+
+    private final Map<Object, String> docIdToShard = new HashMap<>();
+
+    public SkipSecondStepSearchGroupsContainer(String[] fields) {
+      super(fields);
+    }
+
+    @Override
+    public void addSearchGroups(ShardResponse srsp, String field, 
Collection<SearchGroup<BytesRef>> searchGroups) {
+      super.addSearchGroups(srsp, field, searchGroups);
+      for (SearchGroup<BytesRef> searchGroup : searchGroups) {
+        assert(srsp.getShard() != null);
+        docIdToShard.put(searchGroup.topDocSolrId, srsp.getShard());
+      }
+    }
+
+    @Override
+    public void addMergedSearchGroups(ResponseBuilder rb, String groupField, 
Collection<SearchGroup<BytesRef>> mergedTopGroups ) {
+      // TODO: add comment or javadoc re: why this method is overridden as a 
no-op
+    }
+
+    @Override
+    public void addSearchGroupToShards(ResponseBuilder rb, String groupField, 
Collection<SearchGroup<BytesRef>> mergedTopGroups) {
+      super.addSearchGroupToShards(rb, groupField, mergedTopGroups);
+
 
 Review comment:
   So today I was seeking to understand the logic in this 
`SkipSecondStepSearchGroupShardResponseProcessor.addSearchGroupToShards` method 
more.
   
   Analysis:
   * In the existing i.e. `group.skip.second.step=false` code paths 
[QueryComponent.handleGroupedResponses](https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.0.0/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L566-L579)
 logic involves the `SearchGroupShardResponseProcessor` and 
`TopGroupsShardResponseProcessor` classes for the first and second steps 
respectively.
   * In the new i.e. `group.skip.second.step=true` code paths there is no 
second step and so some of what `TopGroupsShardResponseProcessor` would do if 
it was called needs to be done elsewhere.
   * On the `group.skip.second.step=true` code path the 
`SkipSecondStepSearchGroupShardResponseProcessor` is used instead of the 
`SearchGroupShardResponseProcessor` and so structurally there already is a 
possibility for the former to 'do more' than the latter.
   
   Suggestion:
   * Factoring out of a static `TopGroupsShardResponseProcessor.fillResultIds` 
method to reduce code duplication and help ensure both code paths (continue to) 
use the same result ids filling logic (going forward), the 
https://github.com/cpoerschke/lucene-solr/commit/1570f7c0ad0194681897403613e87cfad367d577
 commit has a sketch.
   
   What do you think?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to