From e1ec3e96317731fb916705d3d6bf9d4ccc0cc76a Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Thu, 27 Aug 2015 10:13:46 +0000 Subject: [PATCH] SOLR-7970: Factor out a SearchGroupsFieldCommandResult class. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1698105 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 ++ .../command/SearchGroupsFieldCommand.java | 6 ++-- ...va => SearchGroupsFieldCommandResult.java} | 29 ++++++++++--------- .../SearchGroupShardResponseProcessor.java | 11 +++---- .../SearchGroupsResultTransformer.java | 16 +++++----- 5 files changed, 36 insertions(+), 29 deletions(-) rename solr/core/src/java/org/apache/solr/search/grouping/distributed/command/{Pair.java => SearchGroupsFieldCommandResult.java} (57%) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index e052cd9bc00..647b2917d2c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java index c153e747d3b..a81599ab536 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java @@ -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>>> { +public class SearchGroupsFieldCommand implements Command { public static class Builder { @@ -118,7 +118,7 @@ public class SearchGroupsFieldCommand implements Command>> result() { + public SearchGroupsFieldCommandResult result() { final Collection> topGroups; if (topNGroups > 0) { if (field.getType().getNumericType() != null) { @@ -135,7 +135,7 @@ public class SearchGroupsFieldCommand implements Command(groupCount, topGroups); + return new SearchGroupsFieldCommandResult(groupCount, topGroups); } @Override diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java similarity index 57% rename from solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java rename to solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java index 85af372088b..59157fbcaf6 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommandResult.java @@ -17,26 +17,29 @@ package org.apache.solr.search.grouping.distributed.command; * limitations under the License. */ +import java.util.Collection; + +import org.apache.lucene.search.grouping.SearchGroup; +import org.apache.lucene.util.BytesRef; + /** - * A simple data structure to hold a pair of typed objects. - * - * @lucene.experimental + * Encapsulates the result of a {@link SearchGroupsFieldCommand} command */ -public class Pair { +public class SearchGroupsFieldCommandResult { - private final A a; - private final B b; + private final Integer groupCount; + private final Collection> searchGroups; - public Pair(A a, B b) { - this.a = a; - this.b = b; + public SearchGroupsFieldCommandResult(Integer groupCount, Collection> searchGroups) { + this.groupCount = groupCount; + this.searchGroups = searchGroups; } - public A getA() { - return a; + public Integer getGroupCount() { + return groupCount; } - public B getB() { - return b; + public Collection> getSearchGroups() { + return searchGroups; } } diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java index d5cefc1959e..79f87b768c7 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java @@ -30,7 +30,7 @@ import org.apache.solr.handler.component.ShardRequest; 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 SearchGroupShardResponseProcessor implements ShardResponseProcessor maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime()); @SuppressWarnings("unchecked") NamedList firstPhaseResult = (NamedList) srsp.getSolrResponse().getResponse().get("firstPhase"); - Map>>> result = serializer.transformToNative(firstPhaseResult, groupSort, null, srsp.getShard()); + final Map result = serializer.transformToNative(firstPhaseResult, groupSort, null, srsp.getShard()); for (String field : commandSearchGroups.keySet()) { - Pair>> 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> searchGroups = firstPhaseCommandResult.getB(); + final Collection> searchGroups = firstPhaseCommandResult.getSearchGroups(); if (searchGroups == null) { continue; } diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java index efa7824a51a..707fc75903e 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java @@ -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, Map>>>> { +public class SearchGroupsResultTransformer implements ShardResultTransformer, Map> { private final SolrIndexSearcher searcher; @@ -54,12 +54,12 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer commandResult = new NamedList<>(); if (SearchGroupsFieldCommand.class.isInstance(command)) { SearchGroupsFieldCommand fieldCommand = (SearchGroupsFieldCommand) command; - Pair>> pair = fieldCommand.result(); - Integer groupedCount = pair.getA(); - Collection> searchGroups = pair.getB(); + final SearchGroupsFieldCommandResult fieldCommandResult = fieldCommand.result(); + final Collection> 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 SearchGroupsResultTransformer implements ShardResultTransformer>>> transformToNative(NamedList shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) { - Map>>> result = new HashMap<>(); + public Map transformToNative(NamedList shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) { + final Map result = new HashMap<>(); for (Map.Entry command : shardResponse) { List> searchGroups = new ArrayList<>(); NamedList topGroupsAndGroupCount = command.getValue(); @@ -102,7 +102,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer>>(groupCount, searchGroups)); + result.put(command.getKey(), new SearchGroupsFieldCommandResult(groupCount, searchGroups)); } return result; }