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

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

Introduction

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

Prototype

String CORE_CONFIGSET

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

Click Source Link

Usage

From source file:org.opencms.search.CmsSearchManager.java

License:Open Source License

/**
 * Registers a new Solr core for the given index.<p>
 *
 * @param index the index to register a new Solr core for
 *
 * @throws CmsConfigurationException if no Solr server is configured
 *///from w w w  .  ja v a2 s. c  om
public void registerSolrIndex(CmsSolrIndex index) throws CmsConfigurationException {

    if ((m_solrConfig == null) || !m_solrConfig.isEnabled()) {
        // No solr server configured
        throw new CmsConfigurationException(Messages.get().container(Messages.ERR_SOLR_NOT_ENABLED_0));
    }

    if (m_solrConfig.getServerUrl() != null) {
        // HTTP Server configured
        // TODO Implement multi core support for HTTP server
        // @see http://lucidworks.lucidimagination.com/display/solr/Configuring+solr.xml
        index.setSolrServer(new HttpSolrClient(m_solrConfig.getServerUrl()));
    }

    // get the core container that contains one core for each configured index
    if (m_coreContainer == null) {
        m_coreContainer = createCoreContainer();
    }

    // create a new core if no core exists for the given index
    if (!m_coreContainer.getCoreNames().contains(index.getCoreName())) {
        // Being sure the core container is not 'null',
        // we can create a core for this index if not already existent
        File dataDir = new File(index.getPath());
        if (!dataDir.exists()) {
            dataDir.mkdirs();
            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_INDEX_DIR_CREATED_2,
                        index.getName(), index.getPath()));
            }
        }
        File instanceDir = new File(
                m_solrConfig.getHome() + FileSystems.getDefault().getSeparator() + index.getName());
        if (!instanceDir.exists()) {
            instanceDir.mkdirs();
            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_INDEX_DIR_CREATED_2,
                        index.getName(), index.getPath()));
            }
        }

        // create the core
        // TODO: suboptimal - forces always the same schema
        SolrCore core = null;
        try {
            // creation includes registration.
            // TODO: this was the old code: core = m_coreContainer.create(descriptor, false);
            Map<String, String> properties = new HashMap<String, String>(3);
            properties.put(CoreDescriptor.CORE_DATADIR, dataDir.getAbsolutePath());
            properties.put(CoreDescriptor.CORE_CONFIGSET, "default");
            core = m_coreContainer.create(index.getCoreName(), instanceDir.toPath(), properties);
        } catch (NullPointerException e) {
            if (core != null) {
                core.close();
            }
            throw new CmsConfigurationException(Messages.get().container(Messages.ERR_SOLR_SERVER_NOT_CREATED_3,
                    index.getName() + " (" + index.getCoreName() + ")", index.getPath(),
                    m_solrConfig.getSolrConfigFile().getAbsolutePath()), e);
        }
    }
    if (index.isNoSolrServerSet()) {
        index.setSolrServer(new EmbeddedSolrServer(m_coreContainer, index.getCoreName()));
    }
    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_SERVER_CREATED_1,
                index.getName() + " (" + index.getCoreName() + ")"));
    }
}