List of usage examples for org.apache.solr.core SolrCore getUpdateHandler
public UpdateHandler getUpdateHandler()
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 ww .j a v a2 s .co 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();//www . j av a 2 s . c o m // 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:org.alfresco.solr.AlfrescoCoreAdminTester.java
License:Open Source License
/** * @param req/* ww w .j a v a 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;/*w ww . j a v a2 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 addAcl(SolrCore core, AlfrescoSolrDataModel dataModel, int acltxid, int aclId, int maxReader, int totalReader) throws IOException { AddUpdateCommand aclTxCmd = new AddUpdateCommand(solrQueryRequest); aclTxCmd.overwrite = true;/*from ww w.j a v a 2 s .c o m*/ SolrInputDocument aclTxSol = new SolrInputDocument(); String aclTxId = AlfrescoSolrDataModel.getAclChangeSetDocumentId(new Long(acltxid)); aclTxSol.addField(FIELD_SOLR4_ID, aclTxId); aclTxSol.addField(FIELD_VERSION, "0"); aclTxSol.addField(FIELD_ACLTXID, acltxid); aclTxSol.addField(FIELD_INACLTXID, acltxid); aclTxSol.addField(FIELD_ACLTXCOMMITTIME, (new Date()).getTime()); aclTxSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL_TX); aclTxCmd.solrDoc = aclTxSol; core.getUpdateHandler().addDoc(aclTxCmd); AddUpdateCommand aclCmd = new AddUpdateCommand(solrQueryRequest); aclCmd.overwrite = true; SolrInputDocument aclSol = new SolrInputDocument(); String aclDocId = AlfrescoSolrDataModel.getAclDocumentId(AlfrescoSolrDataModel.DEFAULT_TENANT, new Long(aclId)); aclSol.addField(FIELD_SOLR4_ID, aclDocId); aclSol.addField(FIELD_VERSION, "0"); aclSol.addField(FIELD_ACLID, aclId); aclSol.addField(FIELD_INACLTXID, "" + acltxid); aclSol.addField(FIELD_READER, "GROUP_EVERYONE"); aclSol.addField(FIELD_READER, "pig"); for (int i = 0; i <= maxReader; i++) { aclSol.addField(FIELD_READER, "READER-" + (totalReader - i)); } aclSol.addField(FIELD_DENIED, "something"); aclSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL); aclCmd.solrDoc = aclSol; core.getUpdateHandler().addDoc(aclCmd); }
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 a2s. com 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
/** * /*from www .j a va 2 s . c o 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; }
From source file:org.alfresco.solr.AlfrescoSolrUtils.java
License:Open Source License
/** * Add an acl.// w w w.j a v a2 s. c o m * @param core * @param dataModel * @param acltxid * @param aclId * @param maxReader * @param totalReader * @throws IOException */ public static void addAcl(SolrCore core, AlfrescoSolrDataModel dataModel, int acltxid, int aclId, int maxReader, int totalReader) throws IOException { SolrQueryRequest solrQueryRequest = new SolrServletRequest(core, null); AddUpdateCommand aclTxCmd = new AddUpdateCommand(solrQueryRequest); aclTxCmd.overwrite = true; SolrInputDocument aclTxSol = new SolrInputDocument(); String aclTxId = AlfrescoSolrDataModel.getAclChangeSetDocumentId(new Long(acltxid)); aclTxSol.addField(FIELD_SOLR4_ID, aclTxId); aclTxSol.addField(FIELD_VERSION, "0"); aclTxSol.addField(FIELD_ACLTXID, acltxid); aclTxSol.addField(FIELD_INACLTXID, acltxid); aclTxSol.addField(FIELD_ACLTXCOMMITTIME, (new Date()).getTime()); aclTxSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL_TX); aclTxCmd.solrDoc = aclTxSol; core.getUpdateHandler().addDoc(aclTxCmd); AddUpdateCommand aclCmd = new AddUpdateCommand(solrQueryRequest); aclCmd.overwrite = true; SolrInputDocument aclSol = new SolrInputDocument(); String aclDocId = AlfrescoSolrDataModel.getAclDocumentId(AlfrescoSolrDataModel.DEFAULT_TENANT, new Long(aclId)); aclSol.addField(FIELD_SOLR4_ID, aclDocId); aclSol.addField(FIELD_VERSION, "0"); aclSol.addField(FIELD_ACLID, aclId); aclSol.addField(FIELD_INACLTXID, "" + acltxid); aclSol.addField(FIELD_READER, "GROUP_EVERYONE"); aclSol.addField(FIELD_READER, "pig"); for (int i = 0; i <= maxReader; i++) { aclSol.addField(FIELD_READER, "READER-" + (totalReader - i)); } aclSol.addField(FIELD_DENIED, "something"); aclSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL); aclCmd.solrDoc = aclSol; core.getUpdateHandler().addDoc(aclCmd); }
From source file:org.alfresco.solr.AlfrescoSolrUtils.java
License:Open Source License
/** * Add a store to root. /*from w ww . java 2 s.co m*/ * @param core * @param dataModel * @param rootNodeRef * @param txid * @param dbid * @param acltxid * @param aclid * @throws IOException */ public static void addStoreRoot(SolrCore core, AlfrescoSolrDataModel dataModel, NodeRef rootNodeRef, int txid, int dbid, int acltxid, int aclid) throws IOException { 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), rootNodeRef, ContentModel.TYPE_STOREROOT, new QName[] { ContentModel.ASPECT_ROOT }, null, null, new Long(aclid), new String[] { "/" }, "system", null, null); core.getUpdateHandler().addDoc(addDocCmd); addAcl(solrQueryRequest, core, dataModel, acltxid, aclid, 0, 0); AddUpdateCommand txCmd = new AddUpdateCommand(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(solrQueryRequest, false)); } finally { solrQueryRequest.close(); } }
From source file:org.alfresco.solr.AlfrescoSolrUtils.java
License:Open Source License
public static void addAcl(SolrQueryRequest solrQueryRequest, SolrCore core, AlfrescoSolrDataModel dataModel, int acltxid, int aclId, int maxReader, int totalReader) throws IOException { AddUpdateCommand aclTxCmd = new AddUpdateCommand(solrQueryRequest); aclTxCmd.overwrite = true;/*from w w w . ja va 2s . c om*/ SolrInputDocument aclTxSol = new SolrInputDocument(); String aclTxId = AlfrescoSolrDataModel.getAclChangeSetDocumentId(new Long(acltxid)); aclTxSol.addField(FIELD_SOLR4_ID, aclTxId); aclTxSol.addField(FIELD_VERSION, "0"); aclTxSol.addField(FIELD_ACLTXID, acltxid); aclTxSol.addField(FIELD_INACLTXID, acltxid); aclTxSol.addField(FIELD_ACLTXCOMMITTIME, (new Date()).getTime()); aclTxSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL_TX); aclTxCmd.solrDoc = aclTxSol; core.getUpdateHandler().addDoc(aclTxCmd); AddUpdateCommand aclCmd = new AddUpdateCommand(solrQueryRequest); aclCmd.overwrite = true; SolrInputDocument aclSol = new SolrInputDocument(); String aclDocId = AlfrescoSolrDataModel.getAclDocumentId(AlfrescoSolrDataModel.DEFAULT_TENANT, new Long(aclId)); aclSol.addField(FIELD_SOLR4_ID, aclDocId); aclSol.addField(FIELD_VERSION, "0"); aclSol.addField(FIELD_ACLID, aclId); aclSol.addField(FIELD_INACLTXID, "" + acltxid); aclSol.addField(FIELD_READER, "GROUP_EVERYONE"); aclSol.addField(FIELD_READER, "pig"); for (int i = 0; i <= maxReader; i++) { aclSol.addField(FIELD_READER, "READER-" + (totalReader - i)); } aclSol.addField(FIELD_DENIED, "something"); aclSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL); aclCmd.solrDoc = aclSol; core.getUpdateHandler().addDoc(aclCmd); }