org.apache.solr.search.grouping.distributed.responseprocessor.SearchGroupShardResponseProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* 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.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
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.SearchGroupsFieldCommandResult;
import org.apache.solr.search.grouping.distributed.shardresultserializer.SearchGroupsResultTransformer;
import org.apache.solr.util.SolrResponseUtil;
/** Concrete implementation for merging {@link SearchGroup} instances from shard responses. */
public class SearchGroupShardResponseProcessor implements ShardResponseProcessor {
@Override
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
SortSpec groupSortSpec = rb.getGroupingSpec().getGroupSortSpec();
Sort groupSort = rb.getGroupingSpec().getGroupSortSpec().getSort();
final String[] fields = rb.getGroupingSpec().getFields();
Sort withinGroupSort = rb.getGroupingSpec().getWithinGroupSortSpec().getSort();
assert withinGroupSort != null;
final Map>>> commandSearchGroups =
new HashMap<>(fields.length, 1.0f);
final Map, Set>> tempSearchGroupToShards =
new HashMap<>(fields.length, 1.0f);
for (String field : fields) {
commandSearchGroups.put(field, new ArrayList<>(shardRequest.responses.size()));
tempSearchGroupToShards.put(field, new HashMap<>());
if (!rb.searchGroupToShards.containsKey(field)) {
rb.searchGroupToShards.put(field, new HashMap<>());
}
}
SearchGroupsResultTransformer serializer =
new SearchGroupsResultTransformer(rb.req.getSearcher());
long maxElapsedTime = 0;
int hitCountDuringFirstPhase = 0;
NamedList