Search in sources :

Example 1 with SolrCoreContainer

use of org.codice.solr.factory.impl.SolrCoreContainer 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);
    }
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) InputSource(org.xml.sax.InputSource) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) IOException(java.io.IOException) EmbeddedSolrFactory(org.codice.solr.factory.impl.EmbeddedSolrFactory) SAXException(org.xml.sax.SAXException) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) IndexSchema(org.apache.solr.schema.IndexSchema) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SolrCoreContainer(org.codice.solr.factory.impl.SolrCoreContainer) EmbeddedSolrFactory.getConfigFile(org.codice.solr.factory.impl.EmbeddedSolrFactory.getConfigFile) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)1 CoreDescriptor (org.apache.solr.core.CoreDescriptor)1 SolrConfig (org.apache.solr.core.SolrConfig)1 SolrCore (org.apache.solr.core.SolrCore)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 IndexSchema (org.apache.solr.schema.IndexSchema)1 EmbeddedSolrFactory (org.codice.solr.factory.impl.EmbeddedSolrFactory)1 EmbeddedSolrFactory.getConfigFile (org.codice.solr.factory.impl.EmbeddedSolrFactory.getConfigFile)1 SolrCoreContainer (org.codice.solr.factory.impl.SolrCoreContainer)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1