List of usage examples for org.apache.solr.core CoreContainer getMultiCoreHandler
public CoreAdminHandler getMultiCoreHandler()
From source file:org.alfresco.solr.AdminHandlerDistributedTest.java
License:Open Source License
@Test public void newCoreUsingAdminHandler() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Create the new core AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);//from w w w. j ava2s .c o m SolrCore testingCore = createCoreUsingTemplate(coreContainer, coreAdminHandler, CORE_NAME, "rerank", 1, 1); Properties props = testingCore.getCoreDescriptor().getSubstitutableProperties(); //The default sharding method is DB_ID assertEquals(DB_ID.toString(), props.get("shard.method")); //Call custom actions SolrQueryResponse response = callHandler(coreAdminHandler, testingCore, "check"); assertNotNull(response); response = callHandler(coreAdminHandler, testingCore, "summary"); assertSummaryCorrect(response, testingCore.getName()); response = callHandler(coreAdminHandler, testingCore, "Report"); assertNotNull(response); NamedList<Object> report = (NamedList<Object>) response.getValues().get("report"); assertNotNull(report.get(CORE_NAME)); //Create a core using ACL_ID sharding testingCore = createCoreUsingTemplate(coreContainer, coreAdminHandler, CORE_NAME + "aclId", "rerank", 1, 1, "property.shard.method", ACL_ID.toString()); props = testingCore.getCoreDescriptor().getSubstitutableProperties(); assertEquals(ACL_ID.toString(), props.get("shard.method")); }
From source file:org.alfresco.solr.component.FingerPrintComponent.java
License:Open Source License
private SolrContentStore getContentStore(SolrQueryRequest req) { if (req.getSearcher() != null) { CoreContainer coreContainer = req.getSearcher().getCore().getCoreContainer(); AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer .getMultiCoreHandler();/*from w w w .j a v a 2 s.c o m*/ SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers() .get(req.getSearcher().getCore().getName()); return srv.getSolrContentStore(); } return null; }
From source file:org.alfresco.solr.CoresCreateUpdateDistributedTest.java
License:Open Source License
@Test public void newCoreUsingAllDefaults() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Now create the new core with AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);/*from ww w. ja v a 2 s. c o m*/ createSimpleCore(coreAdminHandler, null, null, null); //Get a reference to the new core SolrCore defaultCore = getCore(coreContainer, "alfresco"); TimeUnit.SECONDS.sleep(3); //Wait a little for background threads to catchup assertNotNull(defaultCore); //Call custom actions SolrQueryResponse response = callHandler(coreAdminHandler, defaultCore, "SUMMARY"); assertSummaryCorrect(response, defaultCore.getName()); }
From source file:org.alfresco.solr.CoresCreateUpdateDistributedTest.java
License:Open Source License
@Test public void newCoreWithUpdateSharedProperties() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Now create the new core with AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);//from ww w.j a v a2s. c o m String coreName = "alfSharedCore"; //First, we have no cores so we can update the shared properties, including disallowed updateShared(coreAdminHandler, "property.solr.host", "myhost", "property.my.property", "chocolate", "property.alfresco.identifier.property.0", "http://www.alfresco.org/model/content/1.0}userName"); Properties props = AlfrescoSolrDataModel.getCommonConfig(); assertEquals(props.getProperty("my.property"), "chocolate"); assertEquals(props.getProperty("alfresco.identifier.property.0"), "http://www.alfresco.org/model/content/1.0}userName"); createSimpleCore(coreAdminHandler, coreName, StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString(), null); //Get a reference to the new core SolrCore defaultCore = getCore(coreContainer, coreName); TimeUnit.SECONDS.sleep(3); //Wait a little for background threads to catchup assertNotNull(defaultCore); String solrHost = props.getProperty("solr.host"); assertFalse(props.containsKey("new.property")); try { updateShared(coreAdminHandler, "property.solr.host", "superhost", "property.new.property", "catchup", "property.alfresco.identifier.property.0", "not_this_time"); assertFalse(true); //Should not get here } catch (SolrException se) { assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, se.code()); } updateShared(coreAdminHandler, "property.solr.host", "superhost", "property.new.property", "catchup"); props = AlfrescoSolrDataModel.getCommonConfig(); assertEquals(props.getProperty("new.property"), "catchup"); assertNotEquals(props.getProperty("solr.host"), solrHost); }
From source file:org.alfresco.solr.CoresCreateUpdateDistributedTest.java
License:Open Source License
@Test public void newCoreUsingArchiveStore() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Now create the new core with AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);// w w w. ja v a 2s . co m String coreName = "archive"; createSimpleCore(coreAdminHandler, coreName, StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.toString(), AlfrescoCoreAdminHandler.DEFAULT_TEMPLATE, "property.alfresco.maxTotalBagels", "99", "property.alfresco.maxTotalConnections", "3456"); //Get a reference to the new core SolrCore defaultCore = getCore(coreContainer, coreName); TimeUnit.SECONDS.sleep(3); //Wait a little for background threads to catchup assertNotNull(defaultCore); //Call custom actions SolrQueryResponse response = callHandler(coreAdminHandler, defaultCore, "SUMMARY"); assertSummaryCorrect(response, defaultCore.getName()); assertEquals("3456", defaultCore.getCoreDescriptor().getCoreProperty("alfresco.maxTotalConnections", "notset")); assertEquals("99", defaultCore.getCoreDescriptor().getCoreProperty("alfresco.maxTotalBagels", "notset")); //Test updating properties updateCore(coreAdminHandler, coreName, "property.alfresco.maxTotalBagels", "101", "property.alfresco.maxTotalConnections", "55", "property.solr.is.great", "true"); defaultCore = getCore(coreContainer, coreName); assertEquals("55", defaultCore.getCoreDescriptor().getCoreProperty("alfresco.maxTotalConnections", "notset")); assertEquals("101", defaultCore.getCoreDescriptor().getCoreProperty("alfresco.maxTotalBagels", "notset")); assertEquals("true", defaultCore.getCoreDescriptor().getCoreProperty("solr.is.great", "notset")); }
From source file:org.alfresco.solr.CoresCreateViaPropertyTest.java
License:Open Source License
@Test public void newCoreUsingAllDefaults() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Now create the new core with AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);// w w w . j av a 2 s. c om TimeUnit.SECONDS.sleep(15); //Wait a little for background threads to catchup //Get a reference to the new core SolrCore defaultCore = getCore(coreContainer, "alfresco"); SolrCore archiveCore = getCore(coreContainer, "archive"); assertNotNull(defaultCore); assertNotNull(archiveCore); }
From source file:org.alfresco.solr.lifecycle.SolrCoreLoadListener.java
License:Open Source License
@Override public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) { CoreContainer coreContainer = getCore().getCoreContainer(); AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); SolrCoreLoadRegistration.registerForCore(coreAdminHandler, coreContainer, getCore(), getCore().getName()); }
From source file:org.alfresco.solr.query.Solr4QueryParser.java
License:Open Source License
/** * Extracts the contentStore from SolrQueryRequest. * @param req// w w w .java 2s .c om * @return */ private SolrContentStore getContentStore(SolrQueryRequest req) { if (req.getSearcher() != null) { CoreContainer coreContainer = req.getSearcher().getCore().getCoreContainer(); AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer .getMultiCoreHandler(); SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers() .get(req.getSearcher().getCore().getName()); return srv.getSolrContentStore(); } return null; }
From source file:org.alfresco.solr.TemplatesDistributedTest.java
License:Open Source License
@Test public void newCoreUsinglshTemplate() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Now create the new core with AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);//from ww w.j a v a 2 s. c o m SolrCore rankCore = createCoreUsingTemplate(coreContainer, coreAdminHandler, "templateWithrerank", AlfrescoCoreAdminHandler.DEFAULT_TEMPLATE, 2, 1); //Call custom actions SolrQueryResponse response = callHandler(coreAdminHandler, rankCore, "SUMMARY"); assertSummaryCorrect(response, rankCore.getName()); }
From source file:org.alfresco.solr.transformer.CachedDocTransformer.java
License:Open Source License
@Override public void transform(SolrDocument doc, int docid, float score) throws IOException { SolrInputDocument cachedDoc = null;/*w w w . j a va 2 s .c o m*/ try { String id = getFieldValueString(doc, FIELD_SOLR4_ID); TenantAclIdDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(id); CoreContainer coreContainer = context.getSearcher().getCore().getCoreContainer(); AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer .getMultiCoreHandler(); SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers() .get(context.getSearcher().getCore().getName()); SolrContentStore solrContentStore = srv.getSolrContentStore(); cachedDoc = solrContentStore.retrieveDocFromSolrContentStore(tenantAndDbId.tenant, tenantAndDbId.dbId); } catch (StringIndexOutOfBoundsException e) { // ignore invalid forms .... } if (cachedDoc != null) { Collection<String> fieldNames = cachedDoc.getFieldNames(); for (String fieldName : fieldNames) { SchemaField schemaField = context.getSearcher().getSchema().getFieldOrNull(fieldName); if (schemaField != null) { doc.removeFields(fieldName); if (schemaField.multiValued()) { int index = fieldName.lastIndexOf("@{"); if (index == -1) { doc.addField(fieldName, cachedDoc.getFieldValues(fieldName)); } else { String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); Collection<Object> values = cachedDoc.getFieldValues(fieldName); //Guard against null pointer in case data model field name does not match up with cachedDoc field name. if (values != null) { ArrayList<Object> newValues = new ArrayList<Object>(values.size()); for (Object value : values) { if (value instanceof String) { String stringValue = (String) value; int start = stringValue.lastIndexOf('\u0000'); if (start == -1) { newValues.add(stringValue); } else { newValues.add(stringValue.substring(start + 1)); } } else { newValues.add(value); } } doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, newValues); } } } else { int index = fieldName.lastIndexOf("@{"); if (index == -1) { doc.addField(fieldName, cachedDoc.getFieldValue(fieldName)); } else { String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); alfrescoFieldName = alfrescoFieldName.contains(":") ? alfrescoFieldName.replace(":", "_") : alfrescoFieldName; Object value = cachedDoc.getFieldValue(fieldName); if (value instanceof String) { String stringValue = (String) value; int start = stringValue.lastIndexOf('\u0000'); if (start == -1) { doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, stringValue); } else { doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, stringValue.substring(start + 1)); } } else { doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, value); } } } } } } }