Search in sources :

Example 16 with DeleteUpdateCommand

use of org.apache.solr.update.DeleteUpdateCommand in project lucene-solr by apache.

the class FieldNameMutatingUpdateProcessorFactory method getInstance.

@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
    return new UpdateRequestProcessor(next) {

        @Override
        public void processAdd(AddUpdateCommand cmd) throws IOException {
            final SolrInputDocument doc = cmd.getSolrInputDocument();
            final Collection<String> fieldNames = new ArrayList<>(doc.getFieldNames());
            for (final String fname : fieldNames) {
                Matcher matcher = pattern.matcher(fname);
                if (matcher.find()) {
                    String newFieldName = matcher.replaceAll(replacement);
                    if (!newFieldName.equals(fname)) {
                        SolrInputField old = doc.remove(fname);
                        old.setName(newFieldName);
                        doc.put(newFieldName, old);
                    }
                }
            }
            super.processAdd(cmd);
        }

        @Override
        public void processDelete(DeleteUpdateCommand cmd) throws IOException {
            super.processDelete(cmd);
        }
    };
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) Matcher(java.util.regex.Matcher) SolrInputField(org.apache.solr.common.SolrInputField) ArrayList(java.util.ArrayList) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 17 with DeleteUpdateCommand

use of org.apache.solr.update.DeleteUpdateCommand in project lucene-solr by apache.

the class DistributedUpdateProcessor method fetchFullUpdateFromLeader.

/**
   * This method is used when an update on which a particular in-place update has been lost for some reason. This method
   * sends a request to the shard leader to fetch the latest full document as seen on the leader.
   * @return AddUpdateCommand containing latest full doc at shard leader for the given id, or null if not found.
   */
private UpdateCommand fetchFullUpdateFromLeader(AddUpdateCommand inplaceAdd, long versionOnUpdate) throws IOException {
    String id = inplaceAdd.getPrintableId();
    UpdateShardHandler updateShardHandler = inplaceAdd.getReq().getCore().getCoreContainer().getUpdateShardHandler();
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(DISTRIB, false);
    params.set("getInputDocument", id);
    params.set("onlyIfActive", true);
    SolrRequest<SimpleSolrResponse> ur = new GenericSolrRequest(METHOD.GET, "/get", params);
    String leaderUrl = req.getParams().get(DISTRIB_FROM);
    if (leaderUrl == null) {
        // leader for the update.
        if (zkController == null) {
            // we should be in cloud mode, but wtf? could be a unit test
            throw new SolrException(ErrorCode.SERVER_ERROR, "Can't find document with id=" + id + ", but fetching from leader " + "failed since we're not in cloud mode.");
        }
        Replica leader;
        try {
            leader = zkController.getZkStateReader().getLeaderRetry(cloudDesc.getCollectionName(), cloudDesc.getShardId());
        } catch (InterruptedException e) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Exception during fetching from leader.", e);
        }
        leaderUrl = leader.getCoreUrl();
    }
    HttpSolrClient hsc = new HttpSolrClient.Builder(leaderUrl).withHttpClient(updateShardHandler.getHttpClient()).build();
    NamedList rsp = null;
    try {
        rsp = hsc.request(ur);
    } catch (SolrServerException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Error during fetching [" + id + "] from leader (" + leaderUrl + "): ", e);
    } finally {
        hsc.close();
    }
    Object inputDocObj = rsp.get("inputDocument");
    Long version = (Long) rsp.get("version");
    SolrInputDocument leaderDoc = (SolrInputDocument) inputDocObj;
    if (leaderDoc == null) {
        // this doc was not found (deleted) on the leader. Lets delete it here as well.
        DeleteUpdateCommand del = new DeleteUpdateCommand(inplaceAdd.getReq());
        del.setIndexedId(inplaceAdd.getIndexedId());
        del.setId(inplaceAdd.getIndexedId().utf8ToString());
        del.setVersion((version == null || version == 0) ? -versionOnUpdate : version);
        return del;
    }
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.solrDoc = leaderDoc;
    cmd.setVersion((long) leaderDoc.getFieldValue(CommonParams.VERSION_FIELD));
    return cmd;
}
Also used : GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) NamedList(org.apache.solr.common.util.NamedList) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) SolrException(org.apache.solr.common.SolrException)

Example 18 with DeleteUpdateCommand

use of org.apache.solr.update.DeleteUpdateCommand in project SearchServices by Alfresco.

the class SolrInformationServer method deleteNode.

private void deleteNode(UpdateRequestProcessor processor, SolrQueryRequest request, long dbid) throws IOException {
    DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
    delDocCmd.setQuery(FIELD_DBID + ":" + dbid);
    processor.processDelete(delDocCmd);
}
Also used : DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand)

Aggregations

DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)18 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)5 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)5 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)5 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)4 SolrException (org.apache.solr.common.SolrException)3 SolrInputField (org.apache.solr.common.SolrInputField)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)3 UpdateCommand (org.apache.solr.update.UpdateCommand)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)2 NamedList (org.apache.solr.common.util.NamedList)2 JsonLoader (org.apache.solr.handler.loader.JsonLoader)2 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)2 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1