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

The following examples show how to use org.apache.solr.client.solrj.request.UpdateRequest#setParams() . 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: SolrTestCaseHS.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Adds a document using the specific client, or to the local test core if null.
 * Returns the version.  TODO: work in progress... version not always returned.  */
public static Long add(SolrClient client, SolrInputDocument sdoc, ModifiableSolrParams params) throws Exception {
  if (client == null) {
    Long version = addAndGetVersion( sdoc, params );
    return version;
  } else {
    UpdateRequest updateRequest = new UpdateRequest();
    if (params != null) {
      updateRequest.setParams(params);
    }
    updateRequest.add( sdoc );
    UpdateResponse rsp = updateRequest.process( client );
    // TODO - return version
    return null;
  }
}
 
Example 2
Source File: TestStressInPlaceUpdates.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected long addDocAndGetVersion(Object... fields) throws Exception {
  SolrInputDocument doc = new SolrInputDocument();
  addFields(doc, fields);

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("versions", "true");

  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(params);
  ureq.add(doc);
  UpdateResponse resp;

  // send updates to leader, to avoid SOLR-8733
  resp = ureq.process(leaderClient);

  long returnedVersion = Long.parseLong(((NamedList) resp.getResponse().get("adds")).getVal(0).toString());
  assertTrue("Due to SOLR-8733, sometimes returned version is 0. Let us assert that we have successfully"
      + " worked around that problem here.", returnedVersion > 0);
  return returnedVersion;
}
 
Example 3
Source File: SolrWriter.java    From anthelion with Apache License 2.0 6 votes vote down vote up
public void close() throws IOException {
  try {
    if (!inputDocs.isEmpty()) {
      LOG.info("Indexing " + Integer.toString(inputDocs.size()) + " documents");
      if (numDeletes > 0) {
        LOG.info("Deleting " + Integer.toString(numDeletes) + " documents");
      }
      UpdateRequest req = new UpdateRequest();
      req.add(inputDocs);
      req.setParams(params);
      req.process(solr);
      inputDocs.clear();
    }
    // solr.commit();
  } catch (final SolrServerException e) {
    throw makeIOException(e);
  }
}
 
Example 4
Source File: SolrCmdDistributor.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void distribDelete(DeleteUpdateCommand cmd, List<Node> nodes, ModifiableSolrParams params, boolean sync,
                          RollupRequestReplicationTracker rollupTracker,
                          LeaderRequestReplicationTracker leaderTracker) throws IOException {
  
  if (!cmd.isDeleteById()) {
    blockAndDoRetries(); // For DBQ, flush all writes before submitting
  }
  
  for (Node node : nodes) {
    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);
    uReq.setCommitWithin(cmd.commitWithin);
    if (cmd.isDeleteById()) {
      uReq.deleteById(cmd.getId(), cmd.getRoute(), cmd.getVersion());
    } else {
      uReq.deleteByQuery(cmd.query);
    }
    submit(new Req(cmd, node, uReq, sync, rollupTracker, leaderTracker), false);
  }
}
 
Example 5
Source File: TestStressInPlaceUpdates.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected long deleteDocAndGetVersion(String id, ModifiableSolrParams params, boolean deleteByQuery) throws Exception {
  params.add("versions", "true");
 
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(params);
  if (deleteByQuery) {
    ureq.deleteByQuery("id:"+id);
  } else {
    ureq.deleteById(id);
  }
  UpdateResponse resp;
  // send updates to leader, to avoid SOLR-8733
  resp = ureq.process(leaderClient);
  
  String key = deleteByQuery? "deleteByQuery": "deletes";
  long returnedVersion = Long.parseLong(((NamedList) resp.getResponse().get(key)).getVal(0).toString());
  assertTrue("Due to SOLR-8733, sometimes returned version is 0. Let us assert that we have successfully"
      + " worked around that problem here.", returnedVersion < 0);
  return returnedVersion;
}
 
Example 6
Source File: SolrCmdDistributor.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void distribCommit(CommitUpdateCommand cmd, List<Node> nodes,
    ModifiableSolrParams params) throws IOException {
  
  // we need to do any retries before commit...
  blockAndDoRetries();
  log.debug("Distrib commit to: {} params: {}", nodes, params);

  for (Node node : nodes) {
    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);

    addCommit(uReq, cmd);
    submit(new Req(cmd, node, uReq, false), true);
  }
  
}
 
Example 7
Source File: SyncSliceTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,
    SolrServerException {
  SolrInputDocument doc = new SolrInputDocument();
  
  addFields(doc, fields);
  addFields(doc, "rnd_b", true);
  
  controlClient.add(doc);
  
  UpdateRequest ureq = new UpdateRequest();
  ureq.add(doc);
  ModifiableSolrParams params = new ModifiableSolrParams();
  for (CloudJettyRunner skip : skipServers) {
    params.add("test.distrib.skip.servers", skip.url + "/");
  }
  ureq.setParams(params);
  ureq.process(cloudClient);
}
 
Example 8
Source File: SolrIndexWriter.java    From nutch-htmlunit with Apache License 2.0 6 votes vote down vote up
public void close() throws IOException {
    try {
        if (!inputDocs.isEmpty()) {
            LOG.info("Indexing " + Integer.toString(inputDocs.size())
                    + " documents");
            if (numDeletes > 0) {
                LOG.info("Deleting " + Integer.toString(numDeletes)
                        + " documents");
            }
            UpdateRequest req = new UpdateRequest();
            req.add(inputDocs);
            req.setParams(params);
            req.process(solr);
            inputDocs.clear();
        }
    } catch (final SolrServerException e) {
        throw makeIOException(e);
    }
}
 
Example 9
Source File: RecoveryStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
final private void commitOnLeader(String leaderUrl) throws SolrServerException,
    IOException {
  try (HttpSolrClient client = buildRecoverySolrClient(leaderUrl)) {
    UpdateRequest ureq = new UpdateRequest();
    ureq.setParams(new ModifiableSolrParams());
    // ureq.getParams().set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
    // ureq.getParams().set(UpdateParams.OPEN_SEARCHER, onlyLeaderIndexes);// Why do we need to open searcher if
    // "onlyLeaderIndexes"?
    ureq.getParams().set(UpdateParams.OPEN_SEARCHER, false);
    ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true).process(
        client);
  }
}
 
Example 10
Source File: PutSolrRecord.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void index(boolean isSolrCloud, String collection, Long commitWithin, String contentStreamPath, MultiMapSolrParams requestParams, List<SolrInputDocument> inputDocumentList)
        throws IOException, SolrServerException,SolrException {
    UpdateRequest request = new UpdateRequest(contentStreamPath);
    request.setParams(new ModifiableSolrParams());

    // add the extra params, don't use 'set' in case of repeating params
    Iterator<String> paramNames = requestParams.getParameterNamesIterator();
    while (paramNames.hasNext()) {
        String paramName = paramNames.next();
        for (String paramValue : requestParams.getParams(paramName)) {
            request.getParams().add(paramName, paramValue);
        }
    }

    // specify the collection for SolrCloud
    if (isSolrCloud) {
        request.setParam(COLLECTION_PARAM_NAME, collection);
    }

    if (commitWithin != null && commitWithin > 0) {
        request.setParam(COMMIT_WITHIN_PARAM_NAME, commitWithin.toString());
    }

    // if a username and password were provided then pass them for basic auth
    if (isBasicAuthEnabled()) {
        request.setBasicAuthCredentials(getUsername(), getPassword());
    }
    request.add(inputDocumentList);
    UpdateResponse response = request.process(getSolrClient());
    getLogger().debug("Got {} response from Solr", new Object[]{response.getStatus()});
    inputDocumentList.clear();
}
 
Example 11
Source File: LeaderFailureAfterFreshStartTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void indexDoc(Object... fields) throws IOException,
    SolrServerException {
  SolrInputDocument doc = new SolrInputDocument();

  addFields(doc, fields);
  addFields(doc, "rnd_s", RandomStringUtils.random(random().nextInt(100) + 100));

  UpdateRequest ureq = new UpdateRequest();
  ureq.add(doc);
  ModifiableSolrParams params = new ModifiableSolrParams();
  ureq.setParams(params);
  ureq.process(cloudClient);
}
 
Example 12
Source File: TestReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private UpdateResponse emptyUpdate(SolrClient client, String... params)
  throws SolrServerException, IOException {

  UpdateRequest req = new UpdateRequest();
  req.setParams(params(params));
  return req.process(client);
}
 
Example 13
Source File: RoutedAliasUpdateProcessorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Adds the docs to Solr via {@link #getSolrClient()} with the params */
@SuppressWarnings("SameParameterValue")
protected UpdateResponse add(String collection, Collection<SolrInputDocument> docs, SolrParams params) throws SolrServerException, IOException {
  UpdateRequest req = new UpdateRequest();
  if (params != null) {
    req.setParams(new ModifiableSolrParams(params));// copy because will be modified
  }
  req.add(docs);
  return req.process(getSolrClient(), collection);
}
 
Example 14
Source File: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static UpdateResponse add(SolrClient client, SolrParams params, SolrInputDocument... sdocs)
        throws IOException, SolrServerException
{
    UpdateRequest ureq = new UpdateRequest();
    ureq.setParams(new ModifiableSolrParams(params));
    for (SolrInputDocument sdoc : sdocs)
    {
        ureq.add(sdoc);
    }
    return ureq.process(client);
}
 
Example 15
Source File: OverseerCollectionMessageHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static UpdateResponse softCommit(String url) throws SolrServerException, IOException {

    try (HttpSolrClient client = new HttpSolrClient.Builder(url)
        .withConnectionTimeout(30000)
        .withSocketTimeout(120000)
        .build()) {
      UpdateRequest ureq = new UpdateRequest();
      ureq.setParams(new ModifiableSolrParams());
      ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true, true);
      return ureq.process(client);
    }
  }
 
Example 16
Source File: BaseDistributedSearchTestCase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected UpdateResponse del(SolrClient client, SolrParams params, Object... ids) throws IOException, SolrServerException {
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(new ModifiableSolrParams(params));
  for (Object id: ids) {
    ureq.deleteById(id.toString());
  }
  return ureq.process(client);
}
 
Example 17
Source File: BaseDistributedSearchTestCase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected UpdateResponse add(SolrClient client, SolrParams params, SolrInputDocument... sdocs) throws IOException, SolrServerException {
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(new ModifiableSolrParams(params));
  for (SolrInputDocument sdoc : sdocs) {
    ureq.add(sdoc);
  }
  return ureq.process(client);
}
 
Example 18
Source File: TestCloudDeleteByQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public static UpdateRequest update(SolrParams params, SolrInputDocument... docs) {
  UpdateRequest r = new UpdateRequest();
  r.setParams(new ModifiableSolrParams(params));
  r.add(Arrays.asList(docs));
  return r;
}
 
Example 19
Source File: TestTolerantUpdateProcessorCloud.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public static UpdateRequest update(SolrParams params, SolrInputDocument... docs) {
  UpdateRequest r = new UpdateRequest();
  r.setParams(new ModifiableSolrParams(params));
  r.add(Arrays.asList(docs));
  return r;
}
 
Example 20
Source File: ShardRoutingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
void doDBQ(String q, String... reqParams) throws Exception {
  UpdateRequest req = new UpdateRequest();
  req.deleteByQuery(q);
  req.setParams(params(reqParams));
  req.process(cloudClient);
}