Search in sources :

Example 86 with AddUpdateCommand

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

the class SolrInformationServer method indexNonShardCascade.

private void indexNonShardCascade(NodeMetaData nodeMetaData) throws IOException {
    canUpdate();
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        StringPropertyValue stringPropertyValue = (StringPropertyValue) nodeMetaData.getProperties().get(ContentModel.PROP_CASCADE_TX);
        List<FieldInstance> fieldInstances = AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields();
        FieldInstance fieldInstance = fieldInstances.get(0);
        AddUpdateCommand cmd = new AddUpdateCommand(request);
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getNodeDocumentId(nodeMetaData.getTenantDomain(), nodeMetaData.getAclId(), nodeMetaData.getId()));
        input.addField(FIELD_VERSION, 0);
        input.addField(fieldInstance.getField(), stringPropertyValue.toString());
        cmd.solrDoc = input;
        processor.processAdd(cmd);
    } finally {
        if (processor != null) {
            processor.finish();
        }
        if (request != null) {
            request.close();
        }
    }
}
Also used : StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) 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) FieldInstance(org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 87 with AddUpdateCommand

use of org.apache.solr.update.AddUpdateCommand 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

AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)87 SolrInputDocument (org.apache.solr.common.SolrInputDocument)59 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 Test (org.junit.Test)34 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)23 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)19 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)17 SolrInputField (org.apache.solr.common.SolrInputField)14 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)14 ArrayList (java.util.ArrayList)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 JsonLoader (org.apache.solr.handler.loader.JsonLoader)11 IOException (java.io.IOException)8 SkipExistingDocumentsUpdateProcessor (org.apache.solr.update.processor.SkipExistingDocumentsProcessorFactory.SkipExistingDocumentsUpdateProcessor)8 SolrException (org.apache.solr.common.SolrException)7 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)7 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)7 SolrCore (org.apache.solr.core.SolrCore)6 NamedList (org.apache.solr.common.util.NamedList)5