mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
c008544464
commit
e1ec3e9631
|
@ -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
|
||||
|
|
|
@ -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 implements Command<Pair<Integer, Collectio
|
|||
}
|
||||
|
||||
@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 implements Command<Pair<Integer, Collectio
|
|||
} else {
|
||||
groupCount = null;
|
||||
}
|
||||
return new Pair<>(groupCount, topGroups);
|
||||
return new SearchGroupsFieldCommandResult(groupCount, topGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<A, B> {
|
||||
public class SearchGroupsFieldCommandResult {
|
||||
|
||||
private final A a;
|
||||
private final B b;
|
||||
private final Integer groupCount;
|
||||
private final Collection<SearchGroup<BytesRef>> searchGroups;
|
||||
|
||||
public Pair(A a, B b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
public SearchGroupsFieldCommandResult(Integer groupCount, Collection<SearchGroup<BytesRef>> searchGroups) {
|
||||
this.groupCount = groupCount;
|
||||
this.searchGroups = searchGroups;
|
||||
}
|
||||
|
||||
public A getA() {
|
||||
return a;
|
||||
public Integer getGroupCount() {
|
||||
return groupCount;
|
||||
}
|
||||
|
||||
public B getB() {
|
||||
return b;
|
||||
public Collection<SearchGroup<BytesRef>> getSearchGroups() {
|
||||
return searchGroups;
|
||||
}
|
||||
}
|
|
@ -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<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;
|
||||
}
|
||||
|
|
|
@ -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 SearchGroupsResultTransformer implements ShardResultTransformer<Lis
|
|||
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 SearchGroupsResultTransformer implements ShardResultTransformer<Lis
|
|||
* {@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 SearchGroupsResultTransformer implements ShardResultTransformer<Lis
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue