use of org.apache.solr.search.grouping.GroupingSpecification in project lucene-solr by apache.
the class SearchGroupsRequestFactory method constructRequest.
/**
* {@inheritDoc}
*/
@Override
public ShardRequest[] constructRequest(ResponseBuilder rb) {
ShardRequest sreq = new ShardRequest();
GroupingSpecification groupingSpecification = rb.getGroupingSpec();
if (groupingSpecification.getFields().length == 0) {
return new ShardRequest[0];
}
sreq.purpose = ShardRequest.PURPOSE_GET_TOP_GROUPS;
sreq.params = new ModifiableSolrParams(rb.req.getParams());
// TODO: base on current params or original params?
// don't pass through any shards param
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");
}
// we could just specify that this is a shard request.
if (rb.shards_rows > -1) {
// if the client set shards.rows set this explicity
sreq.params.set(CommonParams.ROWS, rb.shards_rows);
} else {
sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
}
// in this first phase, request only the unique key field
// and any fields needed for merging.
sreq.params.set(GroupParams.GROUP_DISTRIBUTED_FIRST, "true");
if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score");
} else {
sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName());
}
return new ShardRequest[] { sreq };
}
Aggregations