List of usage examples for org.apache.solr.update CommitUpdateCommand CommitUpdateCommand
public CommitUpdateCommand(SolrQueryRequest req, boolean optimize)
From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java
License:Apache License
private void populate() throws Exception { // populate both indexes SolrCore source = cc.getCore("source"); try {//from w w w. jav a 2 s .c o m for (int i = 99; i >= 0; i--) { AddUpdateCommand cmd = new AddUpdateCommand(makeReq(source)); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "id" + i); doc.addField("side1_t", "foo bar side1 " + i); doc.addField("side2_t", "blah blah side2 " + i); cmd.solrDoc = doc; source.getUpdateHandler().addDoc(cmd); } source.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(source), false)); } finally { source.close(); } SolrCore target = cc.getCore("target"); try { for (int i = 0; i < 101; i++) { AddUpdateCommand cmd = new AddUpdateCommand(makeReq(target)); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "id" + i); doc.addField("text", "document " + i); cmd.solrDoc = doc; target.getUpdateHandler().addDoc(cmd); if (i == 99) { target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false)); } } target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false)); } finally { target.close(); } }
From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java
License:Apache License
@Test public void testChanges() throws Exception { populate();//from w w w .j a va 2s . c om // add some docs, overwriting some of the existing ones SolrCore target = cc.getCore("target"); try { for (int i = 50; i < 150; i++) { AddUpdateCommand cmd = new AddUpdateCommand(makeReq(target)); cmd.overwrite = true; SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "id" + i); doc.addField("text", "new document " + i); cmd.solrDoc = doc; target.getUpdateHandler().addDoc(cmd); } target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false)); } finally { target.close(); } target = cc.getCore("target"); SolrIndexSearcher searcher = target.getSearcher().get(); Query q = new MatchAllDocsQuery(); try { // verify the stored parts TopDocs td = searcher.search(q, 151); assertNotNull(td); for (ScoreDoc sd : td.scoreDocs) { Document doc = searcher.doc(sd.doc); System.err.println(doc); } } finally { searcher.close(); target.close(); } }
From source file:de.qaware.chronix.solr.compaction.SolrUpdateService.java
License:Apache License
/** * Commits open changes to the solr index. Does not optimize the index afterwards. * * @throws IOException iff something goes wrong *//*from w ww . j a v a 2 s . c o m*/ public void commit() throws IOException { updateProcessor.processCommit(new CommitUpdateCommand(req, false)); }
From source file:de.qaware.chronix.solr.ingestion.AbstractIngestionHandler.java
License:Apache License
@Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { formatResponseAsJson(req);/*w w w . j av a2s. co m*/ if (req.getContentStreams() == null) { LOGGER.warn("no content stream"); rsp.add("error", "No content stream"); return; } InputStream stream = req.getContentStreams().iterator().next().getStream(); MetricTimeSeriesConverter converter = new MetricTimeSeriesConverter(); UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(req.getParams()); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); try { for (MetricTimeSeries series : formatParser.parse(stream)) { SolrInputDocument document = new SolrInputDocument(); converter.to(series).getFields().forEach(document::addField); storeDocument(document, processor, req); } LOGGER.debug("Committing transaction..."); processor.processCommit(new CommitUpdateCommand(req, false)); LOGGER.debug("Committed transaction"); } finally { processor.finish(); } }
From source file:de.qaware.chronix.solr.retention.ChronixRetentionHandler.java
License:Apache License
/** * Triggers a commit to make the deletion visible on the index * * @param processor - the update processor do process deletions * @param req - the solr query request information * @throws Exception/*from ww w .j av a2s. c o m*/ */ private void commitDeletions(UpdateRequestProcessor processor, SolrQueryRequest req) throws IOException { CommitUpdateCommand commit = new CommitUpdateCommand(req, optimizeAfterDeletion); commit.softCommit = softCommit; processor.processCommit(commit); }
From source file:lux.solr.XQueryComponent.java
License:Mozilla Public License
protected void doCommit() { boolean isCloud = shards != null && shards.length > 1; SolrQueryRequest req = new SolrQueryRequestBase(core, new ModifiableSolrParams()) { };/*from w w w . j a v a 2 s .c o m*/ CommitUpdateCommand cmd = new CommitUpdateCommand(req, false); cmd.softCommit = true; // cmd.expungeDeletes = false; // cmd.waitFlush = true; // cmd.waitSearcher = true; LoggerFactory.getLogger(getClass()).debug("commit {}", shards); try { if (isCloud) { SolrQueryResponse rsp = new SolrQueryResponse(); // ((ModifiableSolrParams)req.getParams()).add(ShardParams.SHARDS, getShardURLs(false)); UpdateRequestProcessorChain updateChain = core.getUpdateProcessingChain("lux-update-chain"); updateChain.createProcessor(req, rsp).processCommit(cmd); } else { // commit locally core.getUpdateHandler().commit(cmd); } } catch (IOException e) { throw new LuxException(e); } }
From source file:org.alfresco.solr.AlfrescoCoreAdminTester.java
License:Open Source License
/** * @param req//from w w w . j ava 2s . c o m * @param rsp * @throws org.apache.lucene.queryparser.classic.ParseException */ @SuppressWarnings("unused") void runAuthTest(SolrQueryRequest req, SolrQueryResponse rsp) throws org.apache.lucene.queryparser.classic.ParseException { try { boolean remove = true; boolean reuse = true; long count = 100L; long maxReader = 1000; SolrParams params = req.getParams(); if (params.get("remove") != null) { remove = Boolean.valueOf(params.get("remove")); } if (params.get("count") != null) { count = Long.valueOf(params.get("count")); } if (params.get("maxReader") != null) { maxReader = Long.valueOf(params.get("maxReader")); } if (params.get("reuse") != null) { reuse = Boolean.valueOf(params.get("reuse")); } AlfrescoSolrDataModel dataModel = null; String name = "test-auth-" + "" + System.nanoTime(); SolrCore core = null; if (reuse) { for (String coreName : adminHandler.getCoreContainer().getCoreNames()) { if (coreName.startsWith("test-auth-")) { core = adminHandler.getCoreContainer().getCore(coreName); name = coreName; dataModel = AlfrescoSolrDataModel.getInstance(); break; } } } if (core == null) { // copy core from template File solrHome = new File(adminHandler.getCoreContainer().getSolrHome()); File templates = new File(solrHome, "templates"); File template = new File(templates, "test"); File newCore = new File(solrHome, name); AlfrescoCoreAdminHandler.copyDirectory(template, newCore, false); // fix configuration properties File config = new File(newCore, "conf/solrcore.properties"); Properties properties = new Properties(); properties.load(new FileInputStream(config)); properties.setProperty("data.dir.root", newCore.getCanonicalPath()); properties.store(new FileOutputStream(config), null); // add core CoreDescriptor dcore = new CoreDescriptor(adminHandler.getCoreContainer(), name, newCore.toString()); core = adminHandler.getCoreContainer().create(dcore); rsp.add("core", core.getName()); dataModel = AlfrescoSolrDataModel.getInstance(); dataModel.setCMDefaultUri(); this.solrQueryRequest = new SolrServletRequest(core, null); this.solrQueryRequest.setParams(req.getParams()); // add data // Root NodeRef rootNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); addStoreRoot(core, dataModel, rootNodeRef, 1, 1, 1, 1); rsp.add("StoreRootNode", 1); // Base HashMap<QName, PropertyValue> baseFolderProperties = new HashMap<QName, PropertyValue>(); baseFolderProperties.put(ContentModel.PROP_NAME, new StringPropertyValue("Base Folder")); HashMap<QName, String> baseFolderContent = new HashMap<QName, String>(); NodeRef baseFolderNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); QName baseFolderQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "baseFolder"); ChildAssociationRef n01CAR = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, baseFolderQName, baseFolderNodeRef, true, 0); addNode(core, dataModel, 1, 2, 1, ContentModel.TYPE_FOLDER, null, baseFolderProperties, null, "andy", new ChildAssociationRef[] { n01CAR }, new NodeRef[] { rootNodeRef }, new String[] { "/" + baseFolderQName.toString() }, baseFolderNodeRef, true); // Folders HashMap<QName, PropertyValue> folder00Properties = new HashMap<QName, PropertyValue>(); folder00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Folder 0")); HashMap<QName, String> folder00Content = new HashMap<QName, String>(); NodeRef folder00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); QName folder00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Folder 0"); ChildAssociationRef folder00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, baseFolderNodeRef, folder00QName, folder00NodeRef, true, 0); addNode(core, dataModel, 1, 3, 1, ContentModel.TYPE_FOLDER, null, folder00Properties, null, "andy", new ChildAssociationRef[] { folder00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() }, folder00NodeRef, true); for (long i = 0; i < count; i++) { addAcl(core, dataModel, 10 + (int) i, 10 + (int) i, (int) (i % maxReader), (int) maxReader); HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>(); MLTextPropertyValue desc00 = new MLTextPropertyValue(); desc00.addValue(Locale.ENGLISH, "Doc " + i); desc00.addValue(Locale.US, "Doc " + i); content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00); content00Properties.put(ContentModel.PROP_TITLE, desc00); content00Properties.put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.UK, 0l, "UTF-8", "text/plain", null)); content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Doc " + i)); content00Properties.put(ContentModel.PROP_CREATOR, new StringPropertyValue("Test")); content00Properties.put(ContentModel.PROP_MODIFIER, new StringPropertyValue("Test")); content00Properties.put(ContentModel.PROP_VERSION_LABEL, new StringPropertyValue("1.0")); content00Properties.put(ContentModel.PROP_OWNER, new StringPropertyValue("Test")); Date date00 = new Date(); content00Properties.put(ContentModel.PROP_CREATED, new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00))); content00Properties.put(ContentModel.PROP_MODIFIED, new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00))); HashMap<QName, String> content00Content = new HashMap<QName, String>(); content00Content.put(ContentModel.PROP_CONTENT, "Test doc number " + i); NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Doc-" + i); ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef, content00QName, content00NodeRef, true, 0); addNode(core, dataModel, 1, 10 + (int) i, 10 + (int) i, ContentModel.TYPE_CONTENT, new QName[] { ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED }, content00Properties, content00Content, "andy", new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef, folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, false); } core.getUpdateHandler().commit(new CommitUpdateCommand(req, false)); } checkAuth(rsp, core, dataModel, count); // remove core if (remove) { adminHandler.getCoreContainer().unload(name, true, true, true); } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.alfresco.solr.AlfrescoCoreAdminTester.java
License:Open Source License
private NodeRef addNode(SolrCore core, AlfrescoSolrDataModel dataModel, int txid, int dbid, int aclid, QName type, QName[] aspects, Map<QName, PropertyValue> properties, Map<QName, String> content, String owner, ChildAssociationRef[] parentAssocs, NodeRef[] ancestors, String[] paths, NodeRef nodeRef, boolean commit) throws IOException { AddUpdateCommand addDocCmd = new AddUpdateCommand(solrQueryRequest); addDocCmd.overwrite = true;//from www . j ava 2 s . c o m addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), nodeRef, type, aspects, properties, content, new Long(aclid), paths, owner, parentAssocs, ancestors); core.getUpdateHandler().addDoc(addDocCmd); if (commit) { core.getUpdateHandler().commit(new CommitUpdateCommand(solrQueryRequest, false)); } return nodeRef; }
From source file:org.alfresco.solr.AlfrescoCoreAdminTester.java
License:Open Source License
private void addStoreRoot(SolrCore core, AlfrescoSolrDataModel dataModel, NodeRef rootNodeRef, int txid, int dbid, int acltxid, int aclid) throws IOException { AddUpdateCommand addDocCmd = new AddUpdateCommand(this.solrQueryRequest); addDocCmd.overwrite = true;//from w w w . ja v a2 s . c o m addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), rootNodeRef, ContentModel.TYPE_STOREROOT, new QName[] { ContentModel.ASPECT_ROOT }, null, null, new Long(aclid), new String[] { "/" }, "system", null, null); core.getUpdateHandler().addDoc(addDocCmd); addAcl(core, dataModel, acltxid, aclid, 0, 0); AddUpdateCommand txCmd = new AddUpdateCommand(this.solrQueryRequest); txCmd.overwrite = true; SolrInputDocument input = new SolrInputDocument(); String id = AlfrescoSolrDataModel.getTransactionDocumentId(new Long(txid)); input.addField(FIELD_SOLR4_ID, id); input.addField(FIELD_VERSION, "0"); input.addField(FIELD_TXID, txid); input.addField(FIELD_INTXID, txid); input.addField(FIELD_TXCOMMITTIME, (new Date()).getTime()); input.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_TX); txCmd.solrDoc = input; core.getUpdateHandler().addDoc(txCmd); core.getUpdateHandler().commit(new CommitUpdateCommand(this.solrQueryRequest, false)); }
From source file:org.alfresco.solr.AlfrescoSolrUtils.java
License:Open Source License
/** * // w w w . j av a 2s . co m * @param core * @param dataModel * @param txid * @param dbid * @param aclid * @param type * @param aspects * @param properties * @param content * @param owner * @param parentAssocs * @param ancestors * @param paths * @param nodeRef * @param commit * @return * @throws IOException */ public static NodeRef addNode(SolrCore core, AlfrescoSolrDataModel dataModel, int txid, int dbid, int aclid, QName type, QName[] aspects, Map<QName, PropertyValue> properties, Map<QName, String> content, String owner, ChildAssociationRef[] parentAssocs, NodeRef[] ancestors, String[] paths, NodeRef nodeRef, boolean commit) { SolrServletRequest solrQueryRequest = null; try { solrQueryRequest = new SolrServletRequest(core, null); AddUpdateCommand addDocCmd = new AddUpdateCommand(solrQueryRequest); addDocCmd.overwrite = true; addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), nodeRef, type, aspects, properties, content, new Long(aclid), paths, owner, parentAssocs, ancestors); core.getUpdateHandler().addDoc(addDocCmd); if (commit) { core.getUpdateHandler().commit(new CommitUpdateCommand(solrQueryRequest, false)); } } catch (IOException exception) { throw new RuntimeException(exception); } finally { solrQueryRequest.close(); } return nodeRef; }