List of usage examples for org.apache.solr.core SolrConfig getPluginInfo
public PluginInfo getPluginInfo(String type)
From source file:org.codice.solr.factory.EmbeddedSolrFactory.java
License:Open Source License
/** * Provides an already instantiated {@link org.apache.solr.client.solrj.SolrClient} object. If an instance has not already * been instantiated, then the single instance will be instantiated with the provided * configuration file. If an instance already exists, it cannot be overwritten with a new * configuration.// ww w.j av a 2 s. c o m * * @param solrConfigXml the name of the solr configuration filename such as solrconfig.xml * @param schemaXml filename of the schema such as schema.xml * @param givenConfigFileProxy a ConfigurationFileProxy instance. If instance is <code>null</code>, a new * {@link ConfigurationFileProxy} is used instead. * @return {@link org.apache.solr.client.solrj.SolrClient} instance */ public static EmbeddedSolrServer getEmbeddedSolrServer(String solrConfigXml, String schemaXml, ConfigurationFileProxy givenConfigFileProxy) { LOGGER.debug("Retrieving embedded solr with the following properties: [{},{},{}]", solrConfigXml, schemaXml, givenConfigFileProxy); String solrConfigFileName = DEFAULT_SOLRCONFIG_XML; String schemaFileName = DEFAULT_SCHEMA_XML; if (isNotBlank(solrConfigXml)) { solrConfigFileName = solrConfigXml; } if (isNotBlank(schemaXml)) { schemaFileName = schemaXml; } ConfigurationFileProxy configProxy = givenConfigFileProxy; if (givenConfigFileProxy == null) { configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance()); } File solrConfigFile = getConfigFile(solrConfigFileName, configProxy); File solrSchemaFile = getConfigFile(schemaFileName, configProxy); File solrConfigHome = new File(solrConfigFile.getParent()); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(EmbeddedSolrFactory.class.getClassLoader()); // NamedSPILoader uses the thread context classloader to lookup // codecs, posting formats, and analyzers SolrConfig solrConfig = new SolrConfig(Paths.get(solrConfigHome.getParent()), solrConfigFileName, new InputSource(FileUtils.openInputStream(solrConfigFile))); IndexSchema indexSchema = new IndexSchema(solrConfig, schemaFileName, new InputSource(FileUtils.openInputStream(solrSchemaFile))); SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrConfigHome.getAbsolutePath())); SolrCoreContainer container = new SolrCoreContainer(loader); String dataDirPath = null; if (!ConfigurationStore.getInstance().isInMemory()) { File dataDir = configProxy.getDataDirectory(); if (dataDir != null) { LOGGER.debug("Using data directory [{}]", dataDir); dataDirPath = dataDir.getAbsolutePath(); } } else { PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (!"solr.RAMDirectoryFactory".equals(info.className)) { LOGGER.warn("Using in-memory configuration without RAMDirectoryFactory."); } } CoreDescriptor coreDescriptor = new CoreDescriptor(container, DEFAULT_EMBEDDED_CORE_NAME, solrConfig.getResourceLoader().getInstancePath()); SolrCore core = new SolrCore(DEFAULT_EMBEDDED_CORE_NAME, dataDirPath, solrConfig, indexSchema, null, coreDescriptor, null, null, null); container.register(DEFAULT_EMBEDDED_CORE_NAME, core, false); return new EmbeddedSolrServer(container, DEFAULT_EMBEDDED_CORE_NAME); } catch (ParserConfigurationException | IOException | SAXException e) { throw new IllegalArgumentException("Unable to parse Solr configuration file: " + solrConfigFileName, e); } finally { Thread.currentThread().setContextClassLoader(tccl); } }
From source file:org.codice.solr.factory.impl.EmbeddedSolrFactory.java
License:Open Source License
/** * Creates a new {@link EmbeddedSolrServer} using the Solr core and configuration file names, * schema and configuration file proxy provided. * * @param coreName name of the Solr core * @param solrConfigXml name of the Solr configuration file. Defaults to * {@value HttpSolrClientFactory#DEFAULT_SOLRCONFIG_XML} if * {@code null}. * @param schemaXml file name of the Solr core schema. Defaults to * {@value HttpSolrClientFactory#DEFAULT_SCHEMA_XML} if * {@code null}. * @param givenConfigFileProxy {@link ConfigurationFileProxy} instance to use. If {@code null}, * a new {@link ConfigurationFileProxy} will be used. * @return a new {@link EmbeddedSolrServer} instance *//*from ww w . ja v a2 s . c om*/ public static EmbeddedSolrServer getEmbeddedSolrServer(String coreName, @Nullable String solrConfigXml, @Nullable String schemaXml, @Nullable ConfigurationFileProxy givenConfigFileProxy) { LOGGER.debug("Retrieving embedded solr with the following properties: [{},{},{}]", solrConfigXml, schemaXml, givenConfigFileProxy); String solrConfigFileName = HttpSolrClientFactory.DEFAULT_SOLRCONFIG_XML; String schemaFileName = HttpSolrClientFactory.DEFAULT_SCHEMA_XML; if (isNotBlank(solrConfigXml)) { solrConfigFileName = solrConfigXml; } if (isNotBlank(schemaXml)) { schemaFileName = schemaXml; } ConfigurationFileProxy configProxy = givenConfigFileProxy; if (givenConfigFileProxy == null) { configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance()); } configProxy.writeSolrConfiguration(coreName); File solrConfigFile = getConfigFile(solrConfigFileName, configProxy, coreName); File solrSchemaFile = getConfigFile(schemaFileName, configProxy, coreName); if (solrSchemaFile == null) { solrSchemaFile = getConfigFile("managed-schema", configProxy, coreName); if (solrSchemaFile == null) { throw new IllegalArgumentException("Unable to find Solr schema file."); } } File solrConfigHome = new File(solrConfigFile.getParent()); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(EmbeddedSolrFactory.class.getClassLoader()); // NamedSPILoader uses the thread context classloader to lookup // codecs, posting formats, and analyzers SolrConfig solrConfig = new SolrConfig(Paths.get(solrConfigHome.getParent()), solrConfigFileName, new InputSource(FileUtils.openInputStream(solrConfigFile))); IndexSchema indexSchema = new IndexSchema(solrConfig, schemaFileName, new InputSource(FileUtils.openInputStream(solrSchemaFile))); SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrConfigHome.getAbsolutePath())); SolrCoreContainer container = new SolrCoreContainer(loader); String dataDirPath = null; if (!ConfigurationStore.getInstance().isInMemory()) { File dataDir = configProxy.getDataDirectory(); if (dataDir != null) { dataDirPath = Paths.get(dataDir.getAbsolutePath(), coreName, "data").toString(); LOGGER.debug("Using data directory [{}]", dataDirPath); } } else { PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (info != null && !"solr.RAMDirectoryFactory".equals(info.className)) { LOGGER.debug("Using in-memory configuration without RAMDirectoryFactory."); } } CoreDescriptor coreDescriptor = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstancePath()); SolrCore core = new SolrCore(coreName, dataDirPath, solrConfig, indexSchema, null, coreDescriptor, null, null, null); container.register(coreName, core, false); return new EmbeddedSolrServer(container, coreName); } catch (ParserConfigurationException | IOException | SAXException e) { throw new IllegalArgumentException("Unable to parse Solr configuration file: " + solrConfigFileName, e); } finally { Thread.currentThread().setContextClassLoader(tccl); } }
From source file:org.codice.solr.factory.SolrServerFactory.java
License:Open Source License
/** * Provides an already instantiated {@link org.apache.solr.client.solrj.SolrServer} object. If an instance has not already * been instantiated, then the single instance will be instantiated with the provided * configuration file. If an instance already exists, it cannot be overwritten with a new * configuration./*from w ww. ja va2s. c o m*/ * * @param solrConfigXml the name of the solr configuration filename such as solrconfig.xml * @param schemaXml filename of the schema such as schema.xml * @param givenConfigFileProxy a ConfigurationFileProxy instance. If instance is <code>null</code>, a new * {@link ConfigurationFileProxy} is used instead. * @return {@link org.apache.solr.client.solrj.SolrServer} instance */ public static EmbeddedSolrServer getEmbeddedSolrServer(String solrConfigXml, String schemaXml, ConfigurationFileProxy givenConfigFileProxy) { LOGGER.debug("Retrieving embedded solr with the following properties: [{},{},{}]", solrConfigXml, schemaXml, givenConfigFileProxy); String solrConfigFileName = DEFAULT_SOLRCONFIG_XML; String schemaFileName = DEFAULT_SCHEMA_XML; if (isNotBlank(solrConfigXml)) { solrConfigFileName = solrConfigXml; } if (isNotBlank(schemaXml)) { schemaFileName = schemaXml; } ConfigurationFileProxy configProxy = givenConfigFileProxy; if (givenConfigFileProxy == null) { configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance()); } File solrConfigFile = getConfigFile(solrConfigFileName, configProxy); File solrSchemaFile = getConfigFile(schemaFileName, configProxy); File solrFile = getConfigFile(DEFAULT_SOLR_XML, configProxy); File solrConfigHome = new File(solrConfigFile.getParent()); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(SolrServerFactory.class.getClassLoader()); // NamedSPILoader uses the thread context classloader to lookup // codecs, posting formats, and analyzers SolrConfig solrConfig = new SolrConfig(solrConfigHome.getParent(), solrConfigFileName, new InputSource(FileUtils.openInputStream(solrConfigFile))); IndexSchema indexSchema = new IndexSchema(solrConfig, schemaFileName, new InputSource(FileUtils.openInputStream(solrSchemaFile))); SolrResourceLoader loader = new SolrResourceLoader(solrConfigHome.getAbsolutePath()); SolrCoreContainer container = new SolrCoreContainer(loader, solrFile); String dataDirPath = null; if (!ConfigurationStore.getInstance().isInMemory()) { File dataDir = configProxy.getDataDirectory(); if (dataDir != null) { LOGGER.debug("Using data directory [{}]", dataDir); dataDirPath = dataDir.getAbsolutePath(); } } else { PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (!"solr.RAMDirectoryFactory".equals(info.className)) { LOGGER.warn("Using in-memory configuration without RAMDirectoryFactory."); } } CoreDescriptor coreDescriptor = new CoreDescriptor(container, DEFAULT_EMBEDDED_CORE_NAME, solrConfig.getResourceLoader().getInstanceDir()); SolrCore core = new SolrCore(DEFAULT_EMBEDDED_CORE_NAME, dataDirPath, solrConfig, indexSchema, coreDescriptor); container.register(DEFAULT_EMBEDDED_CORE_NAME, core, false); return new EmbeddedSolrServer(container, DEFAULT_EMBEDDED_CORE_NAME); } catch (ParserConfigurationException | IOException | SAXException e) { throw new IllegalArgumentException("Unable to parse Solr configuration file: " + solrConfigFileName, e); } finally { Thread.currentThread().setContextClassLoader(tccl); } }