Java Code Examples for org.apache.solr.handler.component.ShardRequest#PURPOSE_GET_TOP_IDS

The following examples show how to use org.apache.solr.handler.component.ShardRequest#PURPOSE_GET_TOP_IDS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncBuildSuggestComponent.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */
@Override
public int distributedProcess(ResponseBuilder rb) {
  SolrParams params = rb.req.getParams();
  LOG.debug("SuggestComponent distributedProcess with : " + params);
  if (rb.stage < ResponseBuilder.STAGE_EXECUTE_QUERY) 
    return ResponseBuilder.STAGE_EXECUTE_QUERY;
  if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
    ShardRequest sreq = new ShardRequest();
    sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
    sreq.params = new ModifiableSolrParams(rb.req.getParams());
    sreq.params.remove(ShardParams.SHARDS);
    rb.addRequest(this, sreq);
    return ResponseBuilder.STAGE_GET_FIELDS;
  }

  return ResponseBuilder.STAGE_DONE;
}
 
Example 2
Source File: FacetModule.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  FacetComponentState facetState = getFacetComponentState(rb);
  if (facetState == null) return;

  if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
    sreq.purpose |= FacetModule.PURPOSE_GET_JSON_FACETS;
    sreq.params.set(FACET_INFO, "{}"); // The presence of FACET_INFO (_facet_) turns on json faceting
  } else {
    // turn off faceting on other requests
    /*** distributedProcess will need to use other requests for refinement
     sreq.params.remove("json.facet");  // this just saves space... the presence of FACET_INFO really control the faceting
     sreq.params.remove(FACET_INFO);
     **/
  }
}
 
Example 3
Source File: MtasSolrComponentPrefix.java    From mtas with Apache License 2.0 6 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
    if (sreq.params.getBool(PARAM_MTAS_PREFIX, false)
        && (sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
      // do nothing
    } else {
      // remove prefix for other requests
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_PREFIX);
      sreq.params.remove(PARAM_MTAS_PREFIX);
      for (String key : keys) {
        sreq.params.remove(
            PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_FIELD);
        sreq.params.remove(
            PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_KEY);
      }
    }
  }
}
 
Example 4
Source File: MtasSolrComponentCollection.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  // System.out.println(
  // "collection: " + System.nanoTime() + " - " +
  // Thread.currentThread().getId()
  // + " - " + rb.req.getParams().getBool("isShard", false)
  // + " MODIFYREQUEST " + rb.stage + " " + rb.req.getParamString());
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {
    if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
      // do nothing
    } else {
      // remove for other requests
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);
      sreq.params.remove(PARAM_MTAS_COLLECTION);
      for (String key : keys) {
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_ACTION);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_ID);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_FIELD);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_POST);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_KEY);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_URL);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_COLLECTION);
      }
    }
  }
}
 
Example 5
Source File: TopGroupsShardRequestFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
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);

  // set the start (offset) to 0 for each shard request so we can properly merge
  // 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};
}