use of org.apache.solr.core.SolrConfig in project ddf by codice.
the class FilteringSolrIndex method createSolrServer.
private static EmbeddedSolrServer createSolrServer(String coreName, ConfigurationFileProxy configProxy) {
File configFile = getConfigFile(IMMEMORY_SOLRCONFIG_XML, configProxy, coreName);
if (configFile == null) {
throw new IllegalArgumentException("Unable to find Solr configuration file");
}
File schemaFile = getConfigFile(DEFAULT_SCHEMA_XML, configProxy, coreName);
if (schemaFile == null) {
throw new IllegalArgumentException("Unable to find Solr schema file");
}
File solrConfigHome = new File(configFile.getParent());
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(EmbeddedSolrFactory.class.getClassLoader());
SolrConfig solrConfig = new SolrConfig(Paths.get(solrConfigHome.getParent()), IMMEMORY_SOLRCONFIG_XML, new InputSource(FileUtils.openInputStream(configFile)));
if (indexSchema == null) {
indexSchema = new IndexSchema(solrConfig, DEFAULT_SCHEMA_XML, new InputSource(FileUtils.openInputStream(schemaFile)));
}
SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrConfigHome.getAbsolutePath()));
SolrCoreContainer container = new SolrCoreContainer(loader);
CoreDescriptor coreDescriptor = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstancePath());
SolrCore core = new SolrCore(coreName, null, solrConfig, indexSchema, null, coreDescriptor, null, null, null);
container.register(coreName, core, false, true);
return new EmbeddedSolrServer(container, coreName);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new IllegalArgumentException("Unable to parse Solr configuration file", e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
Aggregations