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

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

Introduction

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

Prototype

String CORE_DATADIR

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

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();//from www . j  a  v  a 2 s  .  c om

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

}

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

License:Apache License

private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs
            + ", outputShardDir: " + outputShardDir);

    // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();//from  ww w.ja va  2  s  .co  m
    FileUtils.copyDirectory(solrHomeDir, tmpDir);
    solrHomeDir = tmpDir;

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String.format(Locale.ENGLISH,
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr,
            outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");

    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()),
            ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
        throw new UnsupportedOperationException(
                "Invalid configuration. Currently, the only DirectoryFactory supported is "
                        + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
    return solr;
}

From source file:nl.knaw.huygens.timbuctoo.index.solr.SolrIndexFactory.java

License:Open Source License

@Override
public SolrIndex createIndexFor(VRE vre, Class<? extends DomainEntity> type) {
    String name = getIndexNameFor(vre, type);
    IndexDescription indexDescription = indexDescriptionFactory.create(type);
    AbstractSolrServer abstractSolrServer = solrServerBuilder.setCoreName(name) //
            .addProperty(CoreDescriptor.CORE_DATADIR, getSolrDataDir(name)) //
            .build(indexDescription);//from  www . jav a 2 s  .com
    FacetedSearchLibrary facetedSearchLibrary = facetedSearchLibraryFactory.create(abstractSolrServer);

    String rawSearchField = rawSearchFieldFactory.getRawSearchField(type);

    return new SolrIndex(name, rawSearchField, indexDescription, solrDocumentCreator, abstractSolrServer,
            facetedSearchLibrary);
}

From source file:nl.knaw.huygens.timbuctoo.index.solr.SolrIndexFactoryTest.java

License:Open Source License

@Test
public void testCreateIndex() {
    // setup/*from   ww w .j  a v a2s.  c  o m*/
    String scopeId = "scopeid";
    VRE vre = newVRE().withVreId(scopeId).create();

    Class<? extends DomainEntity> type = Type1.class;
    String indexName = instance.getIndexNameFor(vre, type);

    Index expectedSolrIndex = new SolrIndex(indexName, RAW_SEARCH_FIELD, indexDescription,
            solrInputDocumentCreatorMock, solrServerMock, facetedSearchLibraryMock);

    when(rawSearchFieldFactoryMock.getRawSearchField(type)).thenReturn(RAW_SEARCH_FIELD);
    when(indexDescriptionFactoryMock.create(type)).thenReturn(indexDescription);
    when(solrServerBuilderMock.setCoreName(indexName)).thenReturn(solrServerBuilderMock);
    when(solrServerBuilderMock.build(indexDescription)).thenReturn(solrServerMock);
    when(configurationMock.getSetting(SOLR_DATA_DIR_CONFIG_PROP)).thenReturn(DATA_DIR);
    when(solrServerBuilderMock.addProperty(CoreDescriptor.CORE_DATADIR,
            DATA_DIR + "/" + indexName.replace('.', '/'))).thenReturn(solrServerBuilderMock);
    when(facetedSearchLibraryFactoryMock.create(solrServerMock)).thenReturn(facetedSearchLibraryMock);

    // action
    SolrIndex actualSolrIndex = instance.createIndexFor(vre, type);

    // verify
    assertThat(actualSolrIndex, equalTo(expectedSolrIndex));
}

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 ww  .ja v  a2 s  .c o m*/
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() + ")"));
    }
}