Search in sources :

Example 6 with SolrConfig

use of org.apache.solr.core.SolrConfig in project lucene-solr by apache.

the class XMLLoader method getTransformer.

/** Get Transformer from request context, or from TransformerProvider.
   *  This allows either getContentType(...) or write(...) to instantiate the Transformer,
   *  depending on which one is called first, then the other one reuses the same Transformer
   */
Transformer getTransformer(String xslt, SolrQueryRequest request) throws IOException {
    // not the cleanest way to achieve this
    // no need to synchronize access to context, right? 
    // Nothing else happens with it at the same time
    final Map<Object, Object> ctx = request.getContext();
    Transformer result = (Transformer) ctx.get(CONTEXT_TRANSFORMER_KEY);
    if (result == null) {
        SolrConfig solrConfig = request.getCore().getSolrConfig();
        result = TransformerProvider.instance.getTransformer(solrConfig, xslt, xsltCacheLifetimeSeconds);
        result.setErrorListener(xmllog);
        ctx.put(CONTEXT_TRANSFORMER_KEY, result);
    }
    return result;
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) Transformer(javax.xml.transform.Transformer)

Example 7 with SolrConfig

use of org.apache.solr.core.SolrConfig in project lucene-solr by apache.

the class SolrIndexConfigTest method testToMap.

public void testToMap() throws Exception {
    final String solrConfigFileNameWarmer = solrConfigFileNameWarmerRandomMergePolicyFactory;
    final String solrConfigFileNameTMP = solrConfigFileNameTieredMergePolicyFactory;
    final String solrConfigFileName = (random().nextBoolean() ? solrConfigFileNameWarmer : solrConfigFileNameTMP);
    SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName, null);
    SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
    assertNotNull(solrIndexConfig);
    assertNotNull(solrIndexConfig.mergePolicyFactoryInfo);
    if (solrConfigFileName.equals(solrConfigFileNameWarmerRandomMergePolicyFactory)) {
        assertNotNull(solrIndexConfig.mergedSegmentWarmerInfo);
    } else {
        assertNull(solrIndexConfig.mergedSegmentWarmerInfo);
    }
    assertNotNull(solrIndexConfig.mergeSchedulerInfo);
    Map<String, Object> m = solrIndexConfig.toMap(new LinkedHashMap<>());
    int mSizeExpected = 0;
    ++mSizeExpected;
    assertTrue(m.get("useCompoundFile") instanceof Boolean);
    ++mSizeExpected;
    assertTrue(m.get("maxBufferedDocs") instanceof Integer);
    ++mSizeExpected;
    assertTrue(m.get("ramBufferSizeMB") instanceof Double);
    ++mSizeExpected;
    assertTrue(m.get("writeLockTimeout") instanceof Integer);
    ++mSizeExpected;
    assertTrue(m.get("lockType") instanceof String);
    {
        final String lockType = (String) m.get("lockType");
        assertTrue(DirectoryFactory.LOCK_TYPE_SIMPLE.equals(lockType) || DirectoryFactory.LOCK_TYPE_NATIVE.equals(lockType) || DirectoryFactory.LOCK_TYPE_SINGLE.equals(lockType) || DirectoryFactory.LOCK_TYPE_NONE.equals(lockType) || DirectoryFactory.LOCK_TYPE_HDFS.equals(lockType));
    }
    ++mSizeExpected;
    assertTrue(m.get("infoStreamEnabled") instanceof Boolean);
    {
        assertFalse(Boolean.valueOf(m.get("infoStreamEnabled").toString()).booleanValue());
    }
    ++mSizeExpected;
    assertTrue(m.get("mergeScheduler") instanceof MapSerializable);
    ++mSizeExpected;
    assertTrue(m.get("mergePolicyFactory") instanceof MapSerializable);
    if (solrConfigFileName.equals(solrConfigFileNameWarmerRandomMergePolicyFactory)) {
        ++mSizeExpected;
        assertTrue(m.get("mergedSegmentWarmer") instanceof MapSerializable);
    } else {
        assertNull(m.get("mergedSegmentWarmer"));
    }
    ++mSizeExpected;
    assertNotNull(m.get("metrics"));
    assertEquals(mSizeExpected, m.size());
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) MapSerializable(org.apache.solr.common.MapSerializable)

Example 8 with SolrConfig

use of org.apache.solr.core.SolrConfig in project lucene-solr by apache.

the class SolrIndexConfigTest method testFailingSolrIndexConfigCreation.

@Test
public void testFailingSolrIndexConfigCreation() {
    try {
        SolrConfig solrConfig = new SolrConfig("bad-mpf-solrconfig.xml");
        SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
        IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
        h.getCore().setLatestSchema(indexSchema);
        solrIndexConfig.toIndexWriterConfig(h.getCore());
        fail("a mergePolicy should have an empty constructor in order to be instantiated in Solr thus this should fail ");
    } catch (Exception e) {
    // it failed as expected
    }
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) IndexSchema(org.apache.solr.schema.IndexSchema) Test(org.junit.Test)

Example 9 with SolrConfig

use of org.apache.solr.core.SolrConfig in project lucene-solr by apache.

the class DateFieldTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // set some system properties for use by tests
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    SolrConfig config = new SolrConfig(new SolrResourceLoader(Paths.get(testInstanceDir)), testConfHome + "solrconfig.xml", null);
    IndexSchema schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema.xml", config);
    f = random().nextBoolean() ? new TrieDateField() : new DatePointField();
    f.init(schema, Collections.<String, String>emptyMap());
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrConfig(org.apache.solr.core.SolrConfig)

Example 10 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