Search in sources :

Example 11 with SolrConfig

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);
    }
}
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

SolrConfig (org.apache.solr.core.SolrConfig)11 IndexSchema (org.apache.solr.schema.IndexSchema)6 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)4 IOException (java.io.IOException)3 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 File (java.io.File)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Transformer (javax.xml.transform.Transformer)2 TieredMergePolicy (org.apache.lucene.index.TieredMergePolicy)2 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)2 CoreDescriptor (org.apache.solr.core.CoreDescriptor)2 SolrCore (org.apache.solr.core.SolrCore)2 Test (org.junit.Test)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 ConcurrentMergeScheduler (org.apache.lucene.index.ConcurrentMergeScheduler)1 MergePolicy (org.apache.lucene.index.MergePolicy)1 SimpleMergedSegmentWarmer (org.apache.lucene.index.SimpleMergedSegmentWarmer)1 Sort (org.apache.lucene.search.Sort)1 SortField (org.apache.lucene.search.SortField)1