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