List of usage examples for org.apache.solr.core SolrCore getName
@Override
public String getName()
From source file:com.googlecode.fascinator.indexer.SolrWrapperQueueConsumer.java
License:Open Source License
/** * Initialize a Solr core object.//from w ww . ja v a2 s . c o m * * @param coreName : The core to initialize * @return SolrServer : The initialized core */ private SolrServer initCore(String core) { boolean isEmbedded = globalConfig.getBoolean(false, "indexer", core, "embedded"); try { // Embedded Solr if (isEmbedded) { // Solr over HTTP - Needed to run commits // so the core web server sees them. String uri = globalConfig.getString(null, "indexer", core, "uri"); if (uri == null) { log.error("No URI provided for core: '{}'", core); return null; } URI solrUri = new URI(uri); commit = new CommonsHttpSolrServer(solrUri.toURL()); username = globalConfig.getString(null, "indexer", core, "username"); password = globalConfig.getString(null, "indexer", core, "password"); if (username != null && password != null) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); HttpClient hc = ((CommonsHttpSolrServer) solr).getHttpClient(); hc.getParams().setAuthenticationPreemptive(true); hc.getState().setCredentials(AuthScope.ANY, credentials); } // First time execution if (coreContainer == null) { String home = globalConfig.getString(DEFAULT_SOLR_HOME, "indexer", "home"); log.info("Embedded Solr Home = {}", home); File homeDir = new File(home); if (!homeDir.exists()) { log.error("Solr directory does not exist!"); return null; } System.setProperty("solr.solr.home", homeDir.getAbsolutePath()); File coreXmlFile = new File(homeDir, "solr.xml"); coreContainer = new CoreContainer(homeDir.getAbsolutePath(), coreXmlFile); for (SolrCore aCore : coreContainer.getCores()) { log.info("Loaded core: {}", aCore.getName()); } } String coreName = globalConfig.getString(null, "indexer", core, "coreName"); if (coreName == null) { log.error("No 'coreName' node for core: '{}'", core); return null; } return new EmbeddedSolrServer(coreContainer, coreName); // Solr over HTTP } else { String uri = globalConfig.getString(null, "indexer", core, "uri"); if (uri == null) { log.error("No URI provided for core: '{}'", core); return null; } URI solrUri = new URI(uri); CommonsHttpSolrServer thisCore = new CommonsHttpSolrServer(solrUri.toURL()); username = globalConfig.getString(null, "indexer", core, "username"); password = globalConfig.getString(null, "indexer", core, "password"); if (username != null && password != null) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); HttpClient hc = thisCore.getHttpClient(); hc.getParams().setAuthenticationPreemptive(true); hc.getState().setCredentials(AuthScope.ANY, credentials); } return thisCore; } } catch (MalformedURLException mue) { log.error(core + " : Malformed URL", mue); } catch (URISyntaxException urise) { log.error(core + " : Invalid URI", urise); } catch (IOException ioe) { log.error(core + " : Failed to read Solr configuration", ioe); } catch (ParserConfigurationException pce) { log.error(core + " : Failed to parse Solr configuration", pce); } catch (SAXException saxe) { log.error(core + " : Failed to load Solr configuration", saxe); } return null; }
From source file:com.indoqa.solr.server.factory.EmbeddedSolrServerBuilder.java
License:Apache License
public static SolrServer build(String url, String embeddedSolrConfigurationDir) throws IOException { String solrHome = getNormalizedPath(embeddedSolrConfigurationDir); InputStream solrXmlInputStream = EmbeddedSolrServerBuilder.class .getResourceAsStream("/embedded-core-container/solr.xml"); SolrResourceLoader loader = new SolrResourceLoader(solrHome); ConfigSolr configSolr = ConfigSolr.fromInputStream(loader, solrXmlInputStream); solrXmlInputStream.close();// w w w. ja va2s . co m CoreContainer container = new CoreContainer(loader, configSolr); container.load(); String dataDir = getNormalizedPath(getDataDir(url)); CoreDescriptor coreDescriptor = new CoreDescriptor(container, "Embedded Core", solrHome, CORE_DATADIR, dataDir); SolrCore core = container.create(coreDescriptor); return new EmbeddedSolrServer(container, core.getName()); }
From source file:com.sindicetech.siren.solr.facet.SirenFacetProcessor.java
License:Open Source License
@Override public void processAdd(AddUpdateCommand cmd) throws IOException { SolrCore core = cmd.getReq().getCore(); IndexSchema schema = core.getLatestSchema(); if (!schema.isMutable()) { throw new SolrException(BAD_REQUEST, String.format("This IndexSchema, of core %s, is not mutable.", core.getName())); }//from ww w. j a v a 2 s .c om SolrInputDocument doc = cmd.getSolrInputDocument(); extractor.setSchema(schema); List<SirenFacetEntry> entries = extractor.extractFacets(doc); // update schema // use Sets so that we add a fieldname only once even if it is generated multiple times (for // multiple paths) Set<SchemaField> newFields = new HashSet<SchemaField>(); for (SirenFacetEntry entry : entries) { // skip entry if the field is already in the schema if (schema.getFieldOrNull(entry.toFieldName()) != null) { continue; } TypeMapping typeMapping = getTypeMappingValueClass(entry.datatype.xsdDatatype); // skip facet values that are too large altogether - they don't make sense for faceting if (entry.value instanceof String && ((String) entry.value) .length() > (typeMapping.maxFieldSize != null ? typeMapping.maxFieldSize : DEFAULT_MAX_FACET_VALUE_LENGTH)) { continue; } String fieldTypeName = getTypeMappingValueClass(entry.datatype.xsdDatatype).fieldType; Map<String, Boolean> options = new HashMap<String, Boolean>(); // see FieldProperties.propertyNames[] options.put("indexed", false); options.put("stored", false); options.put("docValues", true); options.put("multiValued", true); newFields.add(schema.newField(entry.toFieldName(), fieldTypeName, options)); } if (!newFields.isEmpty()) { IndexSchema newSchema = schema.addFields(newFields); cmd.getReq().getCore().setLatestSchema(newSchema); cmd.getReq().updateSchemaToLatest(); logger.debug("Successfully added field(s) to the schema."); } // update document for (SirenFacetEntry entry : entries) { TypeMapping typeMapping = getTypeMappingValueClass(entry.datatype.xsdDatatype); // skip facet values that are too large altogether - they don't make sense for faceting if (entry.value instanceof String && ((String) entry.value) .length() > (typeMapping.maxFieldSize != null ? typeMapping.maxFieldSize : DEFAULT_MAX_FACET_VALUE_LENGTH)) { continue; } doc.addField(entry.toFieldName(), entry.value); } // call the next one in chain super.processAdd(cmd); }
From source file:io.logspace.agent.solr.SolrCoreCommitAgent.java
License:Open Source License
public SolrCoreCommitAgent(SolrCore solrCore) { super(solrCore.getName() + "/commit", "solr/core/commit"); this.solrCore = solrCore; SolrCore.log.info("Initializing " + this.getClass().getSimpleName() + " for Core '" + this.solrCore + "'."); this.solrCore.registerNewSearcherListener(this); this.solrCore.getUpdateHandler().registerCommitCallback(this); this.solrCore.getUpdateHandler().registerSoftCommitCallback(this); }
From source file:io.logspace.agent.solr.SolrCoreStatisticsAgent.java
License:Open Source License
public SolrCoreStatisticsAgent(SolrCore solrCore) { super(solrCore.getName() + "/statistics", "solr/core/statistics"); this.solrCore = solrCore; SolrCore.log.info("Initializing " + this.getClass().getSimpleName() + " for Core '" + this.solrCore + "'."); }
From source file:lux.solr.SolrIndexConfig.java
License:Mozilla Public License
public void inform(SolrCore core) { schema = core.getLatestSchema();/* ww w .java 2s . c om*/ // XML_STORE is not listed explicitly by the indexer informField(indexConfig.getField(FieldRole.XML_STORE), core); // This must be run before informField() registers default analyzers with the Schema registerXmlTextFields(); for (FieldDefinition xmlField : indexConfig.getFields()) { informField(xmlField, core); } if (xpathFieldConfig != null) { addXPathFields(); } SchemaField uniqueKeyField = schema.getUniqueKeyField(); if (uniqueKeyField == null) { logger.error("{} schema does not define any unique field", core.getName()); } else if (!uniqueKeyField.getName().equals(indexConfig.getFieldName(FieldRole.URI))) { logger.error( "{} schema defines a different unique field than the uri field declared in lux configuration", core.getName()); } // must call this after making changes to the field map: schema.refreshAnalyzers(); }
From source file:lux.solr.SolrIndexConfig.java
License:Mozilla Public License
private void informField(FieldDefinition xmlField, SolrCore core) { Map<String, SchemaField> schemaFields = schema.getFields(); Map<String, FieldType> fieldTypes = schema.getFieldTypes(); String fieldName = xmlField.getName(); if (schemaFields.containsKey(fieldName) && xmlField.getType() != Type.TOKENS) { // The Solr schema has a definition for this field, but it's not a TOKENS field: // We're only interested in TOKENS fields here; these need to install their own special field type since they wrap the // analyzer defined by the schema return;/*from w w w. j a v a2s .c o m*/ } // look up the type of this field using the mapping in this class FieldType fieldType = getFieldType(xmlField); if (!fieldTypes.containsKey(fieldType.getTypeName())) { // The Solr schema does not define this field type, so add it logger.info("{} defining fieldType: {}", core.getName(), fieldType.getTypeName()); fieldTypes.put(fieldType.getTypeName(), fieldType); } else { fieldType = fieldTypes.get(fieldType.getTypeName()); } // Add the field to the schema logger.info(core.getName() + " defining field: {} of type {}", fieldName, fieldType.getTypeName()); schemaFields.put(fieldName, new SchemaField(fieldName, fieldType, xmlField.getSolrFieldProperties(), "")); }
From source file:org.act.index.server.MetaService.java
License:Apache License
@Override public TreeMap<Integer, CoreInfo> getCore() { // TODO Auto-generated method stub TreeMap<Integer, CoreInfo> cores = new TreeMap<Integer, CoreInfo>(); List<SolrCore> solrCores = (ArrayList<SolrCore>) indexServer.getCoreContainer().getCores(); for (SolrCore solrCore : solrCores) { if (solrCore.getName().compareTo("meta") != 0) { CoreInfo coreInfo = new CoreInfo(solrCore); cores.put(Integer.parseInt(solrCore.getName()), coreInfo); //LOG.info("get core:" + coreInfo.getCoreId()); }//from w w w. ja v a 2s. c om } return cores; }
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);//www. j ava 2 s. 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.AlfrescoCoreAdminHandler.java
License:Open Source License
/** * @param rsp//from w ww. j a v a 2 s. c o m * @param storeRef * @param template * @param coreName * @param newCore * @throws IOException * @throws FileNotFoundException */ private void createAndRegisterNewCore(SolrQueryResponse rsp, Properties extraProperties, StoreRef storeRef, File template, String coreName, File newCore, int shardCount, int shardInstance, String templateName) throws IOException, FileNotFoundException { if (coreContainer.getLoadedCoreNames().contains(coreName)) { //Core alfresco exists LOGGER.warn(coreName + " already exists, not creating again."); rsp.add("core", coreName); return; } FileUtils.copyDirectory(template, newCore, false); // fix configuration properties File config = new File(newCore, "conf/solrcore.properties"); Properties properties = new Properties(); String defaultRoot = newCore.getCanonicalPath(); if (defaultRoot.endsWith(coreName)) defaultRoot = defaultRoot.substring(0, defaultRoot.length() - coreName.length()); //Set defaults properties.setProperty(DATA_DIR_ROOT, defaultRoot); properties.setProperty("data.dir.store", coreName); properties.setProperty("alfresco.stores", storeRef.toString()); //Potentially override the defaults try (FileInputStream fileInputStream = new FileInputStream(config)) { properties.load(fileInputStream); } //Don't override these properties.setProperty("alfresco.template", templateName); if (shardCount > 0) { properties.setProperty("shard.count", "" + shardCount); properties.setProperty("shard.instance", "" + shardInstance); } //Allow "data.dir.root" to be set via config properties.setProperty(DATA_DIR_ROOT, ConfigUtil.locateProperty(DATA_DIR_ROOT, properties.getProperty(DATA_DIR_ROOT))); //Still allow the properties to be overidden via url params if (extraProperties != null && !extraProperties.isEmpty()) { properties.putAll(extraProperties); } try (FileOutputStream fileOutputStream = new FileOutputStream(config)) { properties.store(fileOutputStream, null); } SolrCore core = coreContainer.create(coreName, newCore.toPath(), new HashMap<String, String>(), false); rsp.add("core", core.getName()); }