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

The following examples show how to use org.apache.solr.handler.component.ShardRequest#PURPOSE_GET_FIELDS . 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: MtasSolrComponentDocument.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)
      && sreq.params.getBool(PARAM_MTAS_DOCUMENT, false)) {
    if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      // do nothing
    } else {
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_DOCUMENT);
      sreq.params.remove(PARAM_MTAS_DOCUMENT);
      for (String key : keys) {
        sreq.params.remove(
            PARAM_MTAS_DOCUMENT + "." + key + "." + NAME_MTAS_DOCUMENT_FIELD);
        sreq.params.remove(
            PARAM_MTAS_DOCUMENT + "." + key + "." + NAME_MTAS_DOCUMENT_KEY);
        sreq.params.remove(PARAM_MTAS_DOCUMENT + "." + key + "."
            + NAME_MTAS_DOCUMENT_PREFIX);
      }
    }
  }

}
 
Example 2
Source File: NumFoundSearchComponent.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
	System.out.println("===== MODIFY REQUEST =====");
	System.out.println("who=" + who);
	System.out.println("purpose=" + sreq.purpose);
	if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) > 0) {
		if (fieldListIncludes(rb, DJOIN_FIELD)) {
			Set<String> fl = new HashSet<>(getFieldList(sreq.params));
			fl.add(SHARD_FIELD);
			sreq.params.set(CommonParams.FL, String.join(",", fl));
		}
		
		// enable faceting on shards to get join ids
		sreq.params.set("facet", true);
		sreq.params.set("facet.field", joinField);
	}
}
 
Example 3
Source File: NumFoundSearchComponent.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void handleResponses(ResponseBuilder rb, ShardRequest req) {
	System.out.println("===== HANDLE RESPONSES =====");
	System.out.println("purpose=" + req.purpose);
	System.out.println("Shards: " + (req.shards != null ? String.join(" ", req.shards) : "(null)"));
	if ((req.purpose & ShardRequest.PURPOSE_GET_FIELDS) > 0) {
		Map<String, Long> numFounds = (Map<String, Long>)rb.req.getContext().get(COMPONENT_NAME + "numFounds");
		Set<Object> joinIds = (Set<Object>)rb.req.getContext().get(COMPONENT_NAME + "joinIds");
		for (ShardResponse rsp : req.responses) {
			NamedList response = rsp.getSolrResponse().getResponse();
			SolrDocumentList results = (SolrDocumentList)response.get("response");
			numFounds.put(rsp.getShard(), results.getNumFound());
			NamedList counts = (NamedList)response.get("facet_counts");
			if (counts != null) {
				NamedList fields = (NamedList)counts.get("facet_fields");
				NamedList values = (NamedList)fields.get(joinField);
				for (int i = 0; i < values.size(); ++i) {
					joinIds.add(values.getName(i));
				}
			}
		}
	}
}
 
Example 4
Source File: MtasSolrComponentKwic.java    From mtas with Apache License 2.0 5 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_KWIC, false)
        && (sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      // do nothing
    } else {
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);
      sreq.params.remove(PARAM_MTAS_KWIC);
      for (String key : keys) {
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_PREFIX);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_IGNORE);
        sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "."
            + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT);
      }
    }
  }
}
 
Example 5
Source File: ClusteringComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  SolrParams params = rb.req.getParams();
  if (!params.getBool(COMPONENT_NAME, false) || !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) {
    return;
  }
  sreq.params.remove(COMPONENT_NAME);
  if( ( sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS ) != 0 ){
    String fl = sreq.params.get(CommonParams.FL,"*");
    // if fl=* then we don't need to check.
    if (fl.indexOf('*') >= 0) { 
      return;
    }

    String name = getClusteringEngineName(rb);
    SearchClusteringEngine engine = searchClusteringEngines.get(name);
    if (engine != null) {
      checkAvailable(name, engine);
      Set<String> fields = engine.getFieldsToLoad(rb.req);
      if (fields == null || fields.size() == 0) { 
        return;
      }

      StringBuilder sb = new StringBuilder();
      String[] flparams = fl.split( "[,\\s]+" );
      Set<String> flParamSet = new HashSet<>(flparams.length);
      for (String flparam : flparams) {
        // no need trim() because of split() by \s+
        flParamSet.add(flparam);
      }
      for (String aFieldToLoad : fields) {
        if (!flParamSet.contains(aFieldToLoad )) {
          sb.append(',').append(aFieldToLoad);
        }
      }
      if (sb.length() > 0) {
        sreq.params.set(CommonParams.FL, fl + sb.toString());
      }
    } else {
      log.warn("No engine named: {}", name);
    }
  }
}
 
Example 6
Source File: StoredFieldsShardRequestFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public ShardRequest[] constructRequest(ResponseBuilder rb) {
  HashMap<String, Set<ShardDoc>> shardMap = new HashMap<>();
  for (TopGroups<BytesRef> topGroups : rb.mergedTopGroups.values()) {
    for (GroupDocs<BytesRef> group : topGroups.groups) {
      mapShardToDocs(shardMap, group.scoreDocs);
    }
  }

  for (QueryCommandResult queryCommandResult : rb.mergedQueryCommandResults.values()) {
    mapShardToDocs(shardMap, queryCommandResult.getTopDocs().scoreDocs);
  }

  ShardRequest[] shardRequests = new ShardRequest[shardMap.size()];
  SchemaField uniqueField = rb.req.getSchema().getUniqueKeyField();
  int i = 0;
  for (Collection<ShardDoc> shardDocs : shardMap.values()) {
    ShardRequest sreq = new ShardRequest();
    sreq.purpose = ShardRequest.PURPOSE_GET_FIELDS;
    sreq.shards = new String[] {shardDocs.iterator().next().shard};
    sreq.params = new ModifiableSolrParams();
    sreq.params.add( rb.req.getParams());
    sreq.params.remove(GroupParams.GROUP);
    sreq.params.remove(CommonParams.SORT);
    sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES);
    
    // we need to ensure the uniqueField is included for collating docs with their return fields
    if (! rb.rsp.getReturnFields().wantsField(uniqueField.getName())) {
      // the user didn't ask for it, so we have to...
      sreq.params.add(CommonParams.FL, uniqueField.getName());
    }

    List<String> ids = new ArrayList<>(shardDocs.size());
    for (ShardDoc shardDoc : shardDocs) {
      ids.add(shardDoc.id.toString());
    }
    sreq.params.add(ShardParams.IDS, StrUtils.join(ids, ','));
    shardRequests[i++] = sreq;
  }

  return shardRequests;
}