Search in sources :

Example 6 with GroupingSpecification

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 };
}
Also used : ShardRequest(org.apache.solr.handler.component.ShardRequest) GroupingSpecification(org.apache.solr.search.grouping.GroupingSpecification) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

GroupingSpecification (org.apache.solr.search.grouping.GroupingSpecification)6 SolrException (org.apache.solr.common.SolrException)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 SolrParams (org.apache.solr.common.params.SolrParams)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)4 Query (org.apache.lucene.search.Query)3 BytesRef (org.apache.lucene.util.BytesRef)3 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Term (org.apache.lucene.index.Term)2 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)2 Sort (org.apache.lucene.search.Sort)2 SortField (org.apache.lucene.search.SortField)2 SearchGroup (org.apache.lucene.search.grouping.SearchGroup)2 NamedList (org.apache.solr.common.util.NamedList)2 SchemaField (org.apache.solr.schema.SchemaField)2 Grouping (org.apache.solr.search.Grouping)2 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)2