Java Code Examples for org.apache.solr.update.processor.UpdateRequestProcessor#processAdd()
The following examples show how to use
org.apache.solr.update.processor.UpdateRequestProcessor#processAdd() .
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: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void capIndex(long dbid) throws IOException { UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); SolrInputDocument input = new SolrInputDocument(); input.addField(FIELD_SOLR4_ID, INDEX_CAP_ID); input.addField(FIELD_VERSION, 0); input.addField(FIELD_DBID, -dbid); //Making this negative to ensure it is never confused with node DBID input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = true; cmd.solrDoc = input; processor.processAdd(cmd); } finally { if (processor != null) processor.finish(); } }
Example 2
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
private void putTransactionState(UpdateRequestProcessor processor, SolrQueryRequest request, Transaction tx) throws IOException { SolrDocument txState = getState(core, request, "TRACKER!STATE!TX"); String version = version(txState, FIELD_S_TXCOMMITTIME, FIELD_S_TXID, tx.getCommitTimeMs(), tx.getId()); if (version != null) { SolrInputDocument input = new SolrInputDocument(); input.addField(FIELD_SOLR4_ID, "TRACKER!STATE!TX"); input.addField(FIELD_VERSION, version); input.addField(FIELD_S_TXID, tx.getId()); input.addField(FIELD_S_INTXID, tx.getId()); input.addField(FIELD_S_TXCOMMITTIME, tx.getCommitTimeMs()); input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = true; cmd.solrDoc = input; processor.processAdd(cmd); } }
Example 3
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
private void putAclTransactionState(UpdateRequestProcessor processor, SolrQueryRequest request, AclChangeSet changeSet) throws IOException { SolrDocument aclState = getState(core, request, "TRACKER!STATE!ACLTX"); String version = version(aclState, FIELD_S_ACLTXCOMMITTIME, FIELD_S_ACLTXID, changeSet.getCommitTimeMs(), changeSet.getId()); if (version != null) { SolrInputDocument input = new SolrInputDocument(); input.addField(FIELD_SOLR4_ID, "TRACKER!STATE!ACLTX"); input.addField(FIELD_VERSION, version); input.addField(FIELD_S_ACLTXID, changeSet.getId()); input.addField(FIELD_S_INACLTXID, changeSet.getId()); input.addField(FIELD_S_ACLTXCOMMITTIME, changeSet.getCommitTimeMs()); input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = true; cmd.solrDoc = input; processor.processAdd(cmd); } }
Example 4
Source File: TestNestedUpdateProcessor.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDeeplyNestedURPSanity() throws Exception { SolrInputDocument docHierarchy = sdoc("id", "1", "children", sdocs(sdoc("id", "2", "name_s", "Yaz"), sdoc("id", "3", "name_s", "Jazz", "grandChild", sdoc("id", "4", "name_s", "Gaz"))), "lonelyChild", sdoc("id", "5", "name_s", "Loner")); UpdateRequestProcessor nestedUpdate = new NestedUpdateProcessorFactory().getInstance(req(), null, null); AddUpdateCommand cmd = new AddUpdateCommand(req()); cmd.solrDoc = docHierarchy; nestedUpdate.processAdd(cmd); cmd.clear(); @SuppressWarnings({"rawtypes"}) List children = (List) docHierarchy.get("children").getValues(); SolrInputDocument firstChild = (SolrInputDocument) children.get(0); assertEquals("SolrInputDocument(fields: [id=2, name_s=Yaz, _nest_path_=/children#0, _nest_parent_=1])", firstChild.toString()); SolrInputDocument secondChild = (SolrInputDocument) children.get(1); assertEquals("SolrInputDocument(fields: [id=3, name_s=Jazz, grandChild=SolrInputDocument(fields: [id=4, name_s=Gaz, _nest_path_=/children#1/grandChild#, _nest_parent_=3]), _nest_path_=/children#1, _nest_parent_=1])", secondChild.toString()); SolrInputDocument grandChild = (SolrInputDocument)((SolrInputDocument) children.get(1)).get("grandChild").getValue(); assertEquals("SolrInputDocument(fields: [id=4, name_s=Gaz, _nest_path_=/children#1/grandChild#, _nest_parent_=3])", grandChild.toString()); SolrInputDocument singularChild = (SolrInputDocument) docHierarchy.get("lonelyChild").getValue(); assertEquals("SolrInputDocument(fields: [id=5, name_s=Loner, _nest_path_=/lonelyChild#, _nest_parent_=1])", singularChild.toString()); }
Example 5
Source File: TestNestedUpdateProcessor.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDeeplyNestedURPChildrenWoId() throws Exception { final String rootId = "1"; final String childKey = "grandChild"; final String expectedId = rootId + "/children#1/" + childKey + NUM_SEP_CHAR + SINGLE_VAL_CHAR; SolrInputDocument noIdChildren = sdoc("id", rootId, "children", sdocs(sdoc("name_s", "Yaz"), sdoc("name_s", "Jazz", childKey, sdoc("name_s", "Gaz")))); UpdateRequestProcessor nestedUpdate = new NestedUpdateProcessorFactory().getInstance(req(), null, null); AddUpdateCommand cmd = new AddUpdateCommand(req()); cmd.solrDoc = noIdChildren; nestedUpdate.processAdd(cmd); cmd.clear(); @SuppressWarnings({"rawtypes"}) List children = (List) noIdChildren.get("children").getValues(); SolrInputDocument idLessChild = (SolrInputDocument)((SolrInputDocument) children.get(1)).get(childKey).getValue(); assertTrue("Id less child did not get an Id", idLessChild.containsKey("id")); assertEquals("Id less child was assigned an unexpected id", expectedId, idLessChild.getFieldValue("id").toString()); }
Example 6
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void indexAclTransaction(AclChangeSet changeSet, boolean overwrite) throws IOException { canUpdate(); UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); SolrInputDocument aclTx = new SolrInputDocument(); aclTx.addField(FIELD_SOLR4_ID, getAclChangeSetDocumentId(changeSet.getId())); aclTx.addField(FIELD_VERSION, "0"); aclTx.addField(FIELD_ACLTXID, changeSet.getId()); aclTx.addField(FIELD_INACLTXID, changeSet.getId()); aclTx.addField(FIELD_ACLTXCOMMITTIME, changeSet.getCommitTimeMs()); aclTx.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL_TX); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = overwrite; cmd.solrDoc = aclTx; processor.processAdd(cmd); putAclTransactionState(processor, request, changeSet); } finally { if (processor != null) processor.finish(); } }
Example 7
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void updateTransaction(Transaction txn) throws IOException { canUpdate(); UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = true; SolrInputDocument input = new SolrInputDocument(); input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getTransactionDocumentId(txn.getId())); input.addField(FIELD_VERSION, 1); input.addField(FIELD_TXID, txn.getId()); input.addField(FIELD_INTXID, txn.getId()); input.addField(FIELD_TXCOMMITTIME, txn.getCommitTimeMs()); input.addField(FIELD_DOC_TYPE, DOC_TYPE_TX); if (cascadeTrackingEnabled()) { input.addField(FIELD_CASCADE_FLAG, 0); } cmd.solrDoc = input; processor.processAdd(cmd); } finally { if (processor != null) { processor.finish(); } } }
Example 8
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Index information of a node that does not belong to the current shard. * These information are necessary for cascade tracker to work properly. * The information stored are: * nodeDocumentId, cascadeTx */ private void indexNonShardCascade(NodeMetaData nodeMetaData) throws IOException { UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); 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.getId())); input.addField(FIELD_VERSION, 0); input.addField(fieldInstance.getField(), stringPropertyValue.getValue()); cmd.solrDoc = input; processor.processAdd(cmd); } finally { if (processor != null) { processor.finish(); } } }
Example 9
Source File: TestSchemalessBufferedUpdates.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrInputDocument processAdd(final SolrInputDocument docIn) throws IOException { UpdateRequestProcessorChain processorChain = h.getCore().getUpdateProcessingChain(UPDATE_CHAIN); assertNotNull("Undefined URP chain '" + UPDATE_CHAIN + "'", processorChain); List <UpdateRequestProcessorFactory> factoriesUpToDUP = new ArrayList<>(); for (UpdateRequestProcessorFactory urpFactory : processorChain.getProcessors()) { factoriesUpToDUP.add(urpFactory); if (urpFactory.getClass().equals(DistributedUpdateProcessorFactory.class)) break; } UpdateRequestProcessorChain chainUpToDUP = new UpdateRequestProcessorChain(factoriesUpToDUP, h.getCore()); assertNotNull("URP chain '" + UPDATE_CHAIN + "'", chainUpToDUP); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = req(); try { SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = docIn; UpdateRequestProcessor processor = chainUpToDUP.createProcessor(req, rsp); processor.processAdd(cmd); if (cmd.solrDoc.get("f_dt").getValue() instanceof Date) { // Non-JSON types (Date in this case) aren't handled properly in noggit-0.6. Although this is fixed in // https://github.com/yonik/noggit/commit/ec3e732af7c9425e8f40297463cbe294154682b1 to call obj.toString(), // Date::toString produces a Date representation that Solr doesn't like, so we convert using Instant::toString cmd.solrDoc.get("f_dt").setValue(((Date) cmd.solrDoc.get("f_dt").getValue()).toInstant().toString()); } return cmd.solrDoc; } finally { SolrRequestInfo.clearRequestInfo(); req.close(); } }
Example 10
Source File: AbstractIngestionHandler.java From chronix.server with Apache License 2.0 | 5 votes |
private void storeDocument(SolrInputDocument document, UpdateRequestProcessor processor, SolrQueryRequest req) throws IOException { LOGGER.debug("Adding Solr document..."); AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = document; processor.processAdd(cmd); LOGGER.debug("Added Solr document"); }
Example 11
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public long indexAcl(List<AclReaders> aclReaderList, boolean overwrite) throws IOException { long start = System.nanoTime(); UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); for (AclReaders aclReaders : notNullOrEmpty(aclReaderList)) { SolrInputDocument acl = new SolrInputDocument(); acl.addField(FIELD_SOLR4_ID, getAclDocumentId(aclReaders.getTenantDomain(), aclReaders.getId())); acl.addField(FIELD_VERSION, "0"); acl.addField(FIELD_ACLID, aclReaders.getId()); acl.addField(FIELD_INACLTXID, aclReaders.getAclChangeSetId()); String tenant = aclReaders.getTenantDomain(); for (String reader : notNullOrEmpty(aclReaders.getReaders())) { reader = addTenantToAuthority(reader, tenant); acl.addField(FIELD_READER, reader); } for (String denied : aclReaders.getDenied()) { denied = addTenantToAuthority(denied, tenant); acl.addField(FIELD_DENIED, denied); } acl.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL); AddUpdateCommand cmd = new AddUpdateCommand(request); cmd.overwrite = overwrite; cmd.solrDoc = acl; processor.processAdd(cmd); } } finally { if (processor != null) processor.finish(); } return (System.nanoTime() - start); }
Example 12
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void updateContent(TenantDbId docRef) throws Exception { LOGGER.debug("Text content of Document DBID={} is going to be updated.", docRef.dbId); UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); SolrInputDocument doc = new PartialSolrInputDocument(); doc.removeField(FIELD_DBID); doc.addField(FIELD_DBID, docRef.dbId); doc.setField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getNodeDocumentId( docRef.tenant, docRef.dbId)); if (docRef.optionalBag.containsKey(CONTENT_LOCALE_FIELD)) { addContentToDoc(docRef, doc, docRef.dbId); } LOGGER.debug("Text content of Document DBID={} has been updated (not yet indexed)", docRef.dbId); final Long latestAppliedVersionId = ofNullable(docRef.optionalBag.get(LATEST_APPLIED_CONTENT_VERSION_ID)) .map(String.class::cast) .map(Long::parseLong) .orElse(CONTENT_UPDATED_MARKER); markAsContentInSynch(doc, latestAppliedVersionId); // Add to index AddUpdateCommand addDocCmd = new AddUpdateCommand(request); addDocCmd.overwrite = true; addDocCmd.solrDoc = doc; processor.processAdd(addDocCmd); LOGGER.debug( "Text content of Document DBID={} has been marked as updated (latest content version ID = {})", docRef.dbId, (latestAppliedVersionId == CONTENT_UPDATED_MARKER ? "N.A." : latestAppliedVersionId)); } catch (Exception exception) { LOGGER.error("Unable to update the text content of node {}. See the stacktrace below for further details.", docRef.dbId, exception); } finally { if(processor != null) {processor.finish();} } }
Example 13
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void indexTransaction(Transaction info, boolean overwrite) throws IOException { canUpdate(); UpdateRequestProcessor processor = null; try (SolrQueryRequest request = newSolrQueryRequest()) { processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse()); 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()); if (cascadeTrackingEnabled()) { //Set the cascade flag to 1. This means cascading updates have not been done yet. input.addField(FIELD_CASCADE_FLAG, 1); } cmd.solrDoc = input; processor.processAdd(cmd); putTransactionState(processor, request, info); } finally { if (processor != null) { processor.finish(); } } }
Example 14
Source File: TestSearchPerf.java From lucene-solr with Apache License 2.0 | 4 votes |
void createIndex2(int nDocs, String... fields) throws IOException { Set<String> fieldSet = new HashSet<>(Arrays.asList(fields)); SolrQueryRequest req = lrf.makeRequest(); SolrQueryResponse rsp = new SolrQueryResponse(); UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessingChain(null); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); boolean foomany_s = fieldSet.contains("foomany_s"); boolean foo1_s = fieldSet.contains("foo1_s"); boolean foo2_s = fieldSet.contains("foo2_s"); boolean foo4_s = fieldSet.contains("foo4_s"); boolean foo8_s = fieldSet.contains("foo8_s"); boolean t10_100_ws = fieldSet.contains("t10_100_ws"); for (int i=0; i<nDocs; i++) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id",Float.toString(i)); if (foomany_s) { doc.addField("foomany_s",t(r.nextInt(nDocs*10))); } if (foo1_s) { doc.addField("foo1_s",t(0)); } if (foo2_s) { doc.addField("foo2_s",r.nextInt(2)); } if (foo4_s) { doc.addField("foo4_s",r.nextInt(4)); } if (foo8_s) { doc.addField("foo8_s",r.nextInt(8)); } if (t10_100_ws) { StringBuilder sb = new StringBuilder(9*100); for (int j=0; j<100; j++) { sb.append(' '); sb.append(t(r.nextInt(10))); } doc.addField("t10_100_ws", sb.toString()); } AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = doc; processor.processAdd(cmd); } processor.finish(); processor.close(); req.close(); assertU(commit()); req = lrf.makeRequest(); assertEquals(nDocs, req.getSearcher().maxDoc()); req.close(); }