use of org.apache.solr.handler.component.ShardRequest in project lucene-solr by apache.
the class TopGroupsShardRequestFactory method createRequest.
private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards) {
ShardRequest sreq = new ShardRequest();
sreq.shards = shards;
sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
sreq.params = new ModifiableSolrParams(rb.req.getParams());
// If group.format=simple group.offset doesn't make sense
Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat();
if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) {
sreq.params.remove(GroupParams.GROUP_OFFSET);
}
sreq.params.remove(ShardParams.SHARDS);
// results from the start.
if (rb.shards_start > -1) {
// if the client set shards.start set this explicitly
sreq.params.set(CommonParams.START, rb.shards_start);
} else {
sreq.params.set(CommonParams.START, "0");
}
if (rb.shards_rows > -1) {
// if the client set shards.rows set this explicitly
sreq.params.set(CommonParams.ROWS, rb.shards_rows);
} else {
sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
}
sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true");
final IndexSchema schema = rb.req.getSearcher().getSchema();
for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) {
for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
String groupValue;
if (searchGroup.groupValue != null) {
FieldType fieldType = schema.getField(entry.getKey()).getType();
groupValue = fieldType.indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString();
} else {
groupValue = GROUP_NULL_VALUE;
}
sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue);
}
}
if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName() + ",score");
} else {
sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName());
}
int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1);
if (origTimeAllowed > 0) {
sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1, origTimeAllowed - rb.firstPhaseElapsedTime));
}
return new ShardRequest[] { sreq };
}
Aggregations