Java Code Examples for org.apache.solr.common.util.NamedList#NamedListEntry

The following examples show how to use org.apache.solr.common.util.NamedList#NamedListEntry . 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: TestZKPropertiesWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Code copied with some adaptations from {@link org.apache.solr.util.TestHarness.LocalRequestFactory#makeRequest(String...)}.
 */
@SuppressWarnings({"unchecked"})
private static LocalSolrQueryRequest localMakeRequest(SolrCore core, String ... q) {
  if (q.length==1) {
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.VERSION,"2.2");

    return new LocalSolrQueryRequest(core, q[0], "", 0, 20, args);
  }
  if (q.length%2 != 0) {
    throw new RuntimeException("The length of the string array (query arguments) needs to be even");
  }
  @SuppressWarnings({"rawtypes"})
  Map.Entry<String, String> [] entries = new NamedList.NamedListEntry[q.length / 2];
  for (int i = 0; i < q.length; i += 2) {
    entries[i/2] = new NamedList.NamedListEntry<>(q[i], q[i+1]);
  }
  @SuppressWarnings({"rawtypes"})
  NamedList nl = new NamedList(entries);
  if(nl.get("wt" ) == null) nl.add("wt","xml");
  return new LocalSolrQueryRequest(core, nl);
}
 
Example 2
Source File: TermVectorComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
    
    NamedList<Object> termVectorsNL = new NamedList<>();

    @SuppressWarnings({"unchecked", "rawtypes"})
    Map.Entry<String, Object>[] arr = new NamedList.NamedListEntry[rb.resultIds.size()];

    for (ShardRequest sreq : rb.finished) {
      if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) == 0 || !sreq.params.getBool(COMPONENT_NAME, false)) {
        continue;
      }
      for (ShardResponse srsp : sreq.responses) {
        @SuppressWarnings({"unchecked"})
        NamedList<Object> nl = (NamedList<Object>)srsp.getSolrResponse().getResponse().get(TERM_VECTORS);

        // Add metadata (that which isn't a uniqueKey value):
        Object warningsNL = nl.get(TV_KEY_WARNINGS);
        // assume if that if warnings is already present; we don't need to merge.
        if (warningsNL != null && termVectorsNL.indexOf(TV_KEY_WARNINGS, 0) < 0) {
          termVectorsNL.add(TV_KEY_WARNINGS, warningsNL);
        }

        // UniqueKey data
        SolrPluginUtils.copyNamedListIntoArrayByDocPosInResponse(nl, rb.resultIds, arr);
      }
    }
    // remove nulls in case not all docs were able to be retrieved
    SolrPluginUtils.removeNulls(arr, termVectorsNL);
    rb.rsp.add(TERM_VECTORS, termVectorsNL);
  }
}
 
Example 3
Source File: TestLazyCores.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private LocalSolrQueryRequest makeReq(SolrCore core, String... q) {
  if (q.length == 1) {
    return new LocalSolrQueryRequest(core,
        q[0], null, 0, 20, new HashMap<String, String>());
  }
  if (q.length % 2 != 0) {
    throw new RuntimeException("The length of the string array (query arguments) needs to be even");
  }
  NamedList.NamedListEntry[] entries = new NamedList.NamedListEntry[q.length / 2];
  for (int i = 0; i < q.length; i += 2) {
    entries[i / 2] = new NamedList.NamedListEntry<>(q[i], q[i + 1]);
  }
  return new LocalSolrQueryRequest(core, new NamedList<>(entries));
}
 
Example 4
Source File: HighlightComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes"})
protected Object[] newHighlightsArray(int size) {
  return new NamedList.NamedListEntry[size];
}