Example usage for org.apache.solr.core CoreDescriptor CORE_CONFIG

List of usage examples for org.apache.solr.core CoreDescriptor CORE_CONFIG

Introduction

In this page you can find the example usage for org.apache.solr.core CoreDescriptor CORE_CONFIG.

Prototype

String CORE_CONFIG

To view the source code for org.apache.solr.core CoreDescriptor CORE_CONFIG.

Click Source Link

Usage

From source file:com.indoqa.solr.spring.client.EmbeddedSolrServerBuilder.java

License:Apache License

public static SolrClient build(String url, String embeddedSolrConfigurationPath) {
    if (new File(embeddedSolrConfigurationPath).exists()) {
        deleteOldCoreProperties(embeddedSolrConfigurationPath);

        SolrResourceLoader loader = new SolrResourceLoader(getNormalizedPath(embeddedSolrConfigurationPath));
        NodeConfig nodeConfig = new NodeConfigBuilder(null, loader).build();
        CoreContainer container = new CoreContainer(nodeConfig);
        container.load();/*w  ww .  j av  a 2  s .  c  o  m*/

        Map<String, String> properties = new HashMap<String, String>();
        properties.put(CoreDescriptor.CORE_DATADIR, getNormalizedPath(getDataDir(url)).toString());

        SolrCore core = container.create(CORE_NAME, loader.getInstancePath(), properties);
        return new EmbeddedSolrServer(core);
    }

    // use a temporary directory for the resource loader because Solr needs a real directory for this
    SolrResourceLoader loader = new SolrResourceLoader(createTempDirectory());
    NodeConfig nodeConfig = new NodeConfigBuilder(null, loader).build();
    CoreContainer container = new CoreContainer(nodeConfig);
    container.load();

    Map<String, String> properties = new HashMap<String, String>();
    properties.put(CoreDescriptor.CORE_DATADIR, getNormalizedPath(getDataDir(url)).toString());
    properties.put(CoreDescriptor.CORE_CONFIG, embeddedSolrConfigurationPath + "/conf/solrconfig.xml");
    properties.put(CoreDescriptor.CORE_SCHEMA, embeddedSolrConfigurationPath + "/conf/schema.xml");

    SolrCore core = container.create(CORE_NAME, loader.getInstancePath(), properties);
    return new EmbeddedSolrServer(core);

}