You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2015/08/27 12:13:47 UTC

svn commit: r1698105 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/search/grouping/distributed/command/ core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/ core/src/java/org/apache/solr/search/grouping/distribut...

Author: cpoerschke
Date: Thu Aug 27 10:13:46 2015
New Revision: 1698105

URL: http://svn.apache.org/r1698105
Log:
SOLR-7970: Factor out a SearchGroupsFieldCommandResult class.

Added:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java   (with props)
Removed:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1698105&r1=1698104&r2=1698105&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Aug 27 10:13:46 2015
@@ -209,6 +209,9 @@ Other Changes
 
 * SOLR-7960: Start scripts now gives generic help for bin/solr -h and bin/solr --help (janhoy)
 
+* SOLR-7970: Factor out a SearchGroupsFieldCommandResult class.
+  (Christine Poerschke)
+
 ==================  5.3.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java?rev=1698105&r1=1698104&r2=1698105&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java Thu Aug 27 10:13:46 2015
@@ -38,7 +38,7 @@ import java.util.*;
 /**
  * Creates all the collectors needed for the first phase and how to handle the results.
  */
-public class SearchGroupsFieldCommand implements Command<Pair<Integer, Collection<SearchGroup<BytesRef>>>> {
+public class SearchGroupsFieldCommand implements Command<SearchGroupsFieldCommandResult> {
 
   public static class Builder {
 
@@ -118,7 +118,7 @@ public class SearchGroupsFieldCommand im
   }
 
   @Override
-  public Pair<Integer, Collection<SearchGroup<BytesRef>>> result() {
+  public SearchGroupsFieldCommandResult result() {
     final Collection<SearchGroup<BytesRef>> topGroups;
     if (topNGroups > 0) {
       if (field.getType().getNumericType() != null) {
@@ -135,7 +135,7 @@ public class SearchGroupsFieldCommand im
     } else {
       groupCount = null;
     }
-    return new Pair<>(groupCount, topGroups);
+    return new SearchGroupsFieldCommandResult(groupCount, topGroups);
   }
 
   @Override

Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java?rev=1698105&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java Thu Aug 27 10:13:46 2015
@@ -0,0 +1,45 @@
+package org.apache.solr.search.grouping.distributed.command;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+
+import org.apache.lucene.search.grouping.SearchGroup;
+import org.apache.lucene.util.BytesRef;
+
+/**
+ * Encapsulates the result of a {@link SearchGroupsFieldCommand} command
+ */
+public class SearchGroupsFieldCommandResult {
+
+  private final Integer groupCount;
+  private final Collection<SearchGroup<BytesRef>> searchGroups;
+
+  public SearchGroupsFieldCommandResult(Integer groupCount, Collection<SearchGroup<BytesRef>> searchGroups) {
+    this.groupCount = groupCount;
+    this.searchGroups = searchGroups;
+  }
+
+  public Integer getGroupCount() {
+    return groupCount;
+  }
+
+  public Collection<SearchGroup<BytesRef>> getSearchGroups() {
+    return searchGroups;
+  }
+}

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java?rev=1698105&r1=1698104&r2=1698105&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java Thu Aug 27 10:13:46 2015
@@ -30,7 +30,7 @@ import org.apache.solr.handler.component
 import org.apache.solr.handler.component.ShardResponse;
 import org.apache.solr.search.SortSpec;
 import org.apache.solr.search.grouping.distributed.ShardResponseProcessor;
-import org.apache.solr.search.grouping.distributed.command.Pair;
+import org.apache.solr.search.grouping.distributed.command.SearchGroupsFieldCommandResult;
 import org.apache.solr.search.grouping.distributed.shardresultserializer.SearchGroupsResultTransformer;
 
 import java.io.IOException;
@@ -106,17 +106,18 @@ public class SearchGroupShardResponsePro
         maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime());
         @SuppressWarnings("unchecked")
         NamedList<NamedList> firstPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("firstPhase");
-        Map<String, Pair<Integer, Collection<SearchGroup<BytesRef>>>> result = serializer.transformToNative(firstPhaseResult, groupSort, null, srsp.getShard());
+        final Map<String, SearchGroupsFieldCommandResult> result = serializer.transformToNative(firstPhaseResult, groupSort, null, srsp.getShard());
         for (String field : commandSearchGroups.keySet()) {
-          Pair<Integer, Collection<SearchGroup<BytesRef>>> firstPhaseCommandResult = result.get(field);
-          Integer groupCount = firstPhaseCommandResult.getA();
+          final SearchGroupsFieldCommandResult firstPhaseCommandResult = result.get(field);
+
+          final Integer groupCount = firstPhaseCommandResult.getGroupCount();
           if (groupCount != null) {
             Integer existingGroupCount = rb.mergedGroupCounts.get(field);
             // Assuming groups don't cross shard boundary...
             rb.mergedGroupCounts.put(field, existingGroupCount != null ? existingGroupCount + groupCount : groupCount);
           }
 
-          Collection<SearchGroup<BytesRef>> searchGroups = firstPhaseCommandResult.getB();
+          final Collection<SearchGroup<BytesRef>> searchGroups = firstPhaseCommandResult.getSearchGroups();
           if (searchGroups == null) {
             continue;
           }

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java?rev=1698105&r1=1698104&r2=1698105&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java Thu Aug 27 10:13:46 2015
@@ -27,8 +27,8 @@ import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.search.grouping.Command;
-import org.apache.solr.search.grouping.distributed.command.Pair;
 import org.apache.solr.search.grouping.distributed.command.SearchGroupsFieldCommand;
+import org.apache.solr.search.grouping.distributed.command.SearchGroupsFieldCommandResult;
 
 import java.io.IOException;
 import java.util.*;
@@ -36,7 +36,7 @@ import java.util.*;
 /**
  * Implementation for transforming {@link SearchGroup} into a {@link NamedList} structure and visa versa.
  */
-public class SearchGroupsResultTransformer implements ShardResultTransformer<List<Command>, Map<String, Pair<Integer, Collection<SearchGroup<BytesRef>>>>> {
+public class SearchGroupsResultTransformer implements ShardResultTransformer<List<Command>, Map<String, SearchGroupsFieldCommandResult>> {
 
   private final SolrIndexSearcher searcher;
 
@@ -54,12 +54,12 @@ public class SearchGroupsResultTransform
       final NamedList<Object> commandResult = new NamedList<>();
       if (SearchGroupsFieldCommand.class.isInstance(command)) {
         SearchGroupsFieldCommand fieldCommand = (SearchGroupsFieldCommand) command;
-        Pair<Integer, Collection<SearchGroup<BytesRef>>> pair = fieldCommand.result();
-        Integer groupedCount = pair.getA();
-        Collection<SearchGroup<BytesRef>> searchGroups = pair.getB();
+        final SearchGroupsFieldCommandResult fieldCommandResult = fieldCommand.result();
+        final Collection<SearchGroup<BytesRef>> searchGroups = fieldCommandResult.getSearchGroups();
         if (searchGroups != null) {
           commandResult.add("topGroups", serializeSearchGroup(searchGroups, fieldCommand.getGroupSort()));
         }
+        final Integer groupedCount = fieldCommandResult.getGroupCount();
         if (groupedCount != null) {
           commandResult.add("groupCount", groupedCount);
         }
@@ -76,8 +76,8 @@ public class SearchGroupsResultTransform
    * {@inheritDoc}
    */
   @Override
-  public Map<String, Pair<Integer, Collection<SearchGroup<BytesRef>>>> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) {
-    Map<String, Pair<Integer, Collection<SearchGroup<BytesRef>>>> result = new HashMap<>();
+  public Map<String, SearchGroupsFieldCommandResult> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) {
+    final Map<String, SearchGroupsFieldCommandResult> result = new HashMap<>();
     for (Map.Entry<String, NamedList> command : shardResponse) {
       List<SearchGroup<BytesRef>> searchGroups = new ArrayList<>();
       NamedList topGroupsAndGroupCount = command.getValue();
@@ -102,7 +102,7 @@ public class SearchGroupsResultTransform
       }
 
       Integer groupCount = (Integer) topGroupsAndGroupCount.get("groupCount");
-      result.put(command.getKey(), new Pair<Integer, Collection<SearchGroup<BytesRef>>>(groupCount, searchGroups));
+      result.put(command.getKey(), new SearchGroupsFieldCommandResult(groupCount, searchGroups));
     }
     return result;
   }