List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
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 ww w . j ava 2s .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() + ")")); } }
From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java
License:Open Source License
/** * Private constructor due to usage of the Singleton pattern. * * @param container Solr CoreContainer container object. * @param core The Solr Core object.// w ww . j a v a2 s .co m */ private CmsSolrSpellchecker(CoreContainer container, SolrCore core) { if ((null == container) || (null == core)) { throw new IllegalArgumentException(); } m_core = core; m_coreContainer = container; m_solrClient = new EmbeddedSolrServer(m_coreContainer, m_core.getName()); }
From source file:org.opencommercesearch.EmbeddedSearchServer.java
License:Apache License
private EmbeddedSolrServer createEmbeddedSolrServer(final CoreContainer container, final String collectionName, final Locale locale) { String localizedCollectionName = collectionName + "_" + locale.getLanguage(); return new EmbeddedSolrServer(container, localizedCollectionName); }
From source file:org.openjena.sarq.TestSARQ_Code.java
License:Apache License
@BeforeClass public static void startSolrServer() throws Exception { System.setProperty("solr.solr.home", "solr/sarq"); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); server = new EmbeddedSolrServer(coreContainer, ""); }
From source file:org.openmrs.module.chartsearch.server.EmbeddedSolrServerCreator.java
License:Mozilla Public License
@Override public SolrServer createSolrServer() { // If user has not setup solr config folder, set a default one // TODO use solr functions to determine config folder String configFolderPath = properties.getSolrHome() + File.separatorChar + "collection1" + File.separatorChar + "conf"; File configFolder = new File(configFolderPath); if (configFolder.exists()) { try {/* www. j av a 2s . c o m*/ FileUtils.deleteDirectory(configFolder); } catch (IOException e) { e.printStackTrace(); } } URL url = getClass().getClassLoader().getResource("collection1/conf"); try { File file = new File(url.toURI()); FileUtils.copyDirectoryToDirectory(file, new File(properties.getSolrHome() + File.separatorChar + "collection1")); setDataImportConnectionInfo(configFolderPath); } catch (IOException e) { log.error("Failed to copy Solr config folder", e); } catch (Exception e) { log.error("Failed to set dataImport connection info", e); } // Get the solr home folder // Tell solr that this is our home folder System.setProperty("solr.solr.home", properties.getSolrHome()); log.info(String.format("solr.solr.home: %s", properties.getSolrHome())); /*CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer; try { coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); return solrServer; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (Exception e) { e.printStackTrace(); return null; }*/ CoreContainer coreContainer = new CoreContainer(); try { coreContainer.load(); solrServer = new EmbeddedSolrServer(coreContainer, ""); return solrServer; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.openmrs.module.solr.SolrEngine.java
License:Open Source License
private void init() throws Exception { String solrHome = Context.getAdministrationService().getGlobalProperty("solr.home", new File(OpenmrsUtil.getApplicationDataDirectory(), "solr").getAbsolutePath()); System.setProperty("solr.solr.home", solrHome); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); }
From source file:org.opensextant.solrtexttagger.EmbeddedSolrNoSerializeTest.java
License:Open Source License
@BeforeClass public static void init() throws Exception { initCore("solrconfig.xml", "schema.xml"); solrServer = new EmbeddedSolrServer(h.getCoreContainer(), "collection1"); //we don't need to close the EmbeddedSolrServer because SolrTestCaseJ4 closes the core }
From source file:org.opensextant.util.SolrProxy.java
License:Apache License
/** * Creates an EmbeddedSolrServer given solr home & the core to use. * These may be null and you get the default. * * @param _solrHome solr home//from w w w .ja va2s .c o m * @param _coreName name of core * @return the embedded solr server * @throws ConfigException on err */ public static EmbeddedSolrServer setupCore(String _solrHome, String _coreName) throws ConfigException { try { CoreContainer solrContainer; if (_solrHome == null) { solrContainer = new CoreContainer(); } else { solrContainer = new CoreContainer(_solrHome); } solrContainer.load();// since Solr 4.4 return new EmbeddedSolrServer(solrContainer, _coreName); } catch (Exception err) { throw new ConfigException("Failed to set up Embedded Solr at " + _solrHome + " CORE:" + _coreName, err); } }
From source file:org.orcid.persistence.dao.EmbeddedSolrFactory.java
License:Open Source License
public static SolrServer createInstance(String coreName) throws Exception { if (coreContainer == null) { coreContainer = createCoreContainer(); }// w w w . j a v a2 s. c o m EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); return server; }
From source file:org.outermedia.solrfusion.SolrTestServer.java
License:Open Source License
public SolrTestServer(String solrHome, String solrXmlFile, String coreName) throws Exception { this.solrHome = solrHome; this.solrXmlFile = solrXmlFile; SolrResourceLoader loader = new SolrResourceLoader(solrHome); ConfigSolr config = ConfigSolr.fromFile(loader, getSolrXmlFile()); cc = new CoreContainer(loader, config); cc.load();//w ww . j av a 2s . co m server = new EmbeddedSolrServer(cc, coreName); }