Search in sources :

Example 11 with UpdateRequestProcessor

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

the class SolrInformationServer method hardCommit.

@Override
public void hardCommit() throws IOException {
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try {
        SolrQueryRequest request = null;
        UpdateRequestProcessor processor = null;
        try {
            request = getLocalSolrQueryRequest();
            processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
            CommitUpdateCommand commitUpdateCommand = new CommitUpdateCommand(request, false);
            commitUpdateCommand.openSearcher = false;
            commitUpdateCommand.softCommit = false;
            commitUpdateCommand.waitSearcher = false;
            processor.processCommit(commitUpdateCommand);
        } finally {
            if (processor != null) {
                processor.finish();
            }
            if (request != null) {
                request.close();
            }
        }
    } finally {
        commitAndRollbackLock.writeLock().unlock();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 12 with UpdateRequestProcessor

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

the class SolrInformationServer method capIndex.

public void capIndex(long dbid) throws IOException {
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = true;
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, indexCapId);
        input.addField(FIELD_VERSION, 0);
        // Making this negative to ensure it is never confused with node DBID
        input.addField(FIELD_DBID, -dbid);
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE);
        cmd.solrDoc = input;
        processor.processAdd(cmd);
    } finally {
        if (processor != null) {
            processor.finish();
        }
        if (request != null) {
            request.close();
        }
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 13 with UpdateRequestProcessor

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

the class SolrInformationServer method indexTransaction.

@Override
public void indexTransaction(Transaction info, boolean overwrite) throws IOException {
    canUpdate();
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = overwrite;
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getTransactionDocumentId(info.getId()));
        input.addField(FIELD_VERSION, 0);
        input.addField(FIELD_TXID, info.getId());
        input.addField(FIELD_INTXID, info.getId());
        input.addField(FIELD_TXCOMMITTIME, info.getCommitTimeMs());
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_TX);
        /*
                For backwards compat reasons adding 3 new stored fields. 2 of these fields are duplicate data but there are needed so that
                we can properly update the transaction record for ACE-4284.
            */
        // This fields will be used to update the transaction record
        // They will only be on the record until the cascading updates for this transaction are processed
        input.addField(FIELD_S_TXID, info.getId());
        input.addField(FIELD_S_TXCOMMITTIME, info.getCommitTimeMs());
        // Set the cascade flag to 1. This means cascading updates have not been done yet.
        input.addField(FIELD_CASCADE_FLAG, 1);
        cmd.solrDoc = input;
        // System.out.println("############### Adding transaction:"+ input);
        processor.processAdd(cmd);
        putTransactionState(processor, request, info);
    } finally {
        if (processor != null) {
            processor.finish();
        }
        if (request != null) {
            request.close();
        }
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 14 with UpdateRequestProcessor

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

the class QueryLoggingComponent method log.

private void log(ResponseBuilder rb) throws IOException {
    boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
    if (!isShard) {
        CoreContainer container = rb.req.getCore().getCoreContainer();
        SolrCore logCore = container.getCore(rb.req.getCore().getName() + "_qlog");
        if (logCore != null) {
            JSONObject json = (JSONObject) rb.req.getContext().get(AbstractQParser.ALFRESCO_JSON);
            SolrQueryRequest request = null;
            UpdateRequestProcessor processor = null;
            try {
                request = new LocalSolrQueryRequest(logCore, new NamedList<>());
                processor = logCore.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
                AddUpdateCommand cmd = new AddUpdateCommand(request);
                cmd.overwrite = true;
                SolrInputDocument input = new SolrInputDocument();
                input.addField("id", GUID.generate());
                input.addField("_version_", "1");
                input.addField("timestamp", DateTimeFormatter.ISO_INSTANT.format(Instant.now()));
                if (json != null) {
                    try {
                        ArrayList<String> authorityList = new ArrayList<String>(1);
                        JSONArray authorities = json.getJSONArray("authorities");
                        for (int i = 0; i < authorities.length(); i++) {
                            String authorityString = authorities.getString(i);
                            authorityList.add(authorityString);
                        }
                        for (String authority : authorityList) {
                            if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER) {
                                input.addField("user", authority);
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        input.addField("user", "<UNKNOWN>");
                    }
                } else {
                    input.addField("user", "<UNKNOWN>");
                }
                String userQuery = rb.req.getParams().get(SpellingParams.SPELLCHECK_Q);
                if (userQuery == null) {
                    if (json != null) {
                        try {
                            userQuery = json.getString("query");
                        } catch (JSONException e) {
                        }
                    }
                }
                if (userQuery == null) {
                    userQuery = rb.req.getParams().get(CommonParams.Q);
                }
                if (userQuery != null) {
                    input.addField("user_query", userQuery);
                }
                Query query = rb.getQuery();
                input.addField("query", query.toString());
                if (rb.getResults().docList != null) {
                    input.addField("found", rb.getResults().docList.matches());
                }
                input.addField("time", rb.req.getRequestTimer().getTime());
                cmd.solrDoc = input;
                processor.processAdd(cmd);
            } finally {
                if (processor != null) {
                    processor.finish();
                }
                if (request != null) {
                    request.close();
                }
            }
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) CoreContainer(org.apache.solr.core.CoreContainer) JSONObject(org.json.JSONObject) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 15 with UpdateRequestProcessor

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

the class SolrInformationServer method cascadeNodes.

public void cascadeNodes(List<NodeMetaData> nodeMetaDatas, boolean overwrite) throws IOException, AuthenticationException, JSONException {
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        for (NodeMetaData nodeMetaData : nodeMetaDatas) {
            if (mayHaveChildren(nodeMetaData)) {
                cascadeUpdateV2(nodeMetaData, overwrite, request, processor);
            }
        }
    } catch (Exception e) {
        for (NodeMetaData node : nodeMetaDatas) {
        // TODO Add a cascadeNode method
        }
    } finally {
        if (processor != null) {
            processor.finish();
        }
        if (request != null) {
            request.close();
        }
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NodeMetaData(org.alfresco.solr.client.NodeMetaData) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) JSONException(org.json.JSONException) AuthenticationException(org.alfresco.httpclient.AuthenticationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)26 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)21 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)20 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)19 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)14 SolrInputDocument (org.apache.solr.common.SolrInputDocument)13 UpdateRequestProcessorChain (org.apache.solr.update.processor.UpdateRequestProcessorChain)10 IOException (java.io.IOException)5 SolrCore (org.apache.solr.core.SolrCore)5 JSONException (org.json.JSONException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AuthenticationException (org.alfresco.httpclient.AuthenticationException)4 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)4 NodeMetaData (org.alfresco.solr.client.NodeMetaData)3 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)3 SolrException (org.apache.solr.common.SolrException)3 SolrParams (org.apache.solr.common.params.SolrParams)3 NamedList (org.apache.solr.common.util.NamedList)3