Java Code Examples for org.apache.solr.client.solrj.request.UpdateRequest#getParams()

The following examples show how to use org.apache.solr.client.solrj.request.UpdateRequest#getParams() . 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: ReplicationFactorTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void sendNonDirectUpdateRequestReplica(Replica replica, UpdateRequest up, int expectedRf, String collection) throws Exception {
  ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
  String url = zkProps.getBaseUrl() + "/" + collection;
  try (HttpSolrClient solrServer = getHttpSolrClient(url)) {
    NamedList resp = solrServer.request(up);
    NamedList hdr = (NamedList) resp.get("responseHeader");
    Integer batchRf = (Integer)hdr.get(UpdateRequest.REPFACT);
    // Note that this also tests if we're wonky and return an achieved rf greater than the number of live replicas.
    assertTrue("Expected rf="+expectedRf+" for batch but got "+
        batchRf + "; clusterState: " + printClusterStateInfo(), batchRf == expectedRf);
    if (up.getParams() != null && up.getParams().get(UpdateRequest.MIN_REPFACT) != null) {
      // If "min_rf" was specified in the request, it must be in the response for back compatibility
      assertNotNull("Expecting min_rf to be in the response, since it was explicitly set in the request", hdr.get(UpdateRequest.MIN_REPFACT));
      assertEquals("Unexpected min_rf in the response",
          Integer.parseInt(up.getParams().get(UpdateRequest.MIN_REPFACT)), hdr.get(UpdateRequest.MIN_REPFACT));
    }
  }
}
 
Example 2
Source File: Http2SolrClient.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public OutStream initOutStream(String baseUrl,
                               UpdateRequest updateRequest,
                               String collection) throws IOException {
  String contentType = requestWriter.getUpdateContentType();
  final ModifiableSolrParams origParams = new ModifiableSolrParams(updateRequest.getParams());

  // The parser 'wt=' and 'version=' params are used instead of the
  // original params
  ModifiableSolrParams requestParams = new ModifiableSolrParams(origParams);
  requestParams.set(CommonParams.WT, parser.getWriterType());
  requestParams.set(CommonParams.VERSION, parser.getVersion());

  String basePath = baseUrl;
  if (collection != null)
    basePath += "/" + collection;
  if (!basePath.endsWith("/"))
    basePath += "/";

  OutputStreamContentProvider provider = new OutputStreamContentProvider();
  Request postRequest = httpClient
      .newRequest(basePath + "update"
          + requestParams.toQueryString())
      .method(HttpMethod.POST)
      .header(HttpHeader.CONTENT_TYPE, contentType)
      .content(provider);
  decorateRequest(postRequest, updateRequest);
  InputStreamResponseListener responseListener = new InputStreamResponseListener();
  postRequest.send(responseListener);

  boolean isXml = ClientUtils.TEXT_XML.equals(requestWriter.getUpdateContentType());
  OutStream outStream = new OutStream(collection, origParams, provider, responseListener,
      isXml);
  if (isXml) {
    outStream.write("<stream>".getBytes(FALLBACK_CHARSET));
  }
  return outStream;
}
 
Example 3
Source File: JavabinLoader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void delete(SolrQueryRequest req, UpdateRequest update, UpdateRequestProcessor processor) throws IOException {
  SolrParams params = update.getParams();
  DeleteUpdateCommand delcmd = new DeleteUpdateCommand(req);
  if(params != null) {
    delcmd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
  }
  
  if(update.getDeleteByIdMap() != null) {
    Set<Entry<String,Map<String,Object>>> entries = update.getDeleteByIdMap().entrySet();
    for (Entry<String,Map<String,Object>> e : entries) {
      delcmd.id = e.getKey();
      Map<String,Object> map = e.getValue();
      if (map != null) {
        Long version = (Long) map.get("ver");
        if (version != null) {
          delcmd.setVersion(version);
        }
      }
      if (map != null) {
        String route = (String) map.get(ShardParams._ROUTE_);
        if (route != null) {
          delcmd.setRoute(route);
        }
      }
      processor.processDelete(delcmd);
      delcmd.clear();
    }
  }
  
  if(update.getDeleteQuery() != null) {
    for (String s : update.getDeleteQuery()) {
      delcmd.query = s;
      processor.processDelete(delcmd);
    }
  }
}
 
Example 4
Source File: SendToSolrCloudProcessorTest.java    From jesterj with Apache License 2.0 5 votes vote down vote up
@Test
public void testPerBatchOperationWithChain() throws IOException, SolrServerException {
  ConcurrentBiMap<Document, SolrInputDocument> biMap = expect3Docs();

  Map<String,String> params = new HashMap<>();
  params.put("update.chain", "myCustomChain");

  expect(proc.getParams()).andReturn(params).anyTimes();
  expect(proc.getSolrClient()).andReturn(solrClientMock).anyTimes();
  Capture<UpdateRequest> addCap = newCapture();
  Capture<List<String>> delCap = newCapture();
  //noinspection ConstantConditions
  expect(solrClientMock.request(capture(addCap), eq(null))).andReturn(namedListMock);
  expect(solrClientMock.deleteById(capture(delCap))).andReturn(deleteResponseMock);

  expectLogging();
  replay();
  proc.batchOperation(biMap);

  assertEquals("42", delCap.getValue().get(0));
  UpdateRequest updateRequest = addCap.getValue();
  List<SolrInputDocument> documents = updateRequest.getDocuments();
  assertTrue(documents.contains(inputDocMock));
  assertFalse(documents.contains(inputDocMock2));
  assertTrue(documents.contains(inputDocMock3));
  ModifiableSolrParams reqParams = updateRequest.getParams();
  assertEquals("myCustomChain", reqParams.get("update.chain"));
}