Search in sources :

Example 26 with UpdateRequestProcessor

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

the class SolrInformationServer method updateContentToIndexAndCache.

@Override
public void updateContentToIndexAndCache(long dbId, String tenant) throws Exception {
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        if (!spinLock(dbId, 120000)) {
            throw new Exception("Unable to acquire spinlock for node:" + dbId);
        }
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        SolrInputDocument doc = solrContentStore.retrieveDocFromSolrContentStore(tenant, dbId);
        if (doc == null) {
            log.warn("There is no cached doc in the Solr content store with tenant [" + tenant + "] and dbId [" + dbId + "].\n" + "This should only happen if the content has been removed from the Solr content store.\n" + "Recreating cached doc ... ");
            doc = recreateSolrDoc(dbId, tenant);
            // This is a work around for ACE-3228/ACE-3258 and the way stores are expunged when deleting a tenant
            if (doc == null) {
                deleteNode(processor, request, dbId);
            }
        }
        if (doc != null) {
            addContentToDoc(doc, dbId);
            // Marks as clean since the doc's content is now up to date
            markFTSStatus(doc, FTSStatus.Clean);
            solrContentStore.storeDocOnSolrContentStore(tenant, dbId, doc);
            // Add to index
            AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
            addDocCmd.overwrite = true;
            addDocCmd.solrDoc = doc;
            // System.out.println("############# indexing content:"+doc);
            processor.processAdd(addDocCmd);
        }
    } finally {
        unlock(dbId);
        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) 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