List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
From source file:org.springframework.data.solr.server.support.SolrClientFactoryBean.java
License:Apache License
/** * {@inheritDoc}/*ww w . j a v a2s.c o m*/ */ @Override public SolrClient getSolrClient(final String core) { if (isEmbedded()) { if (embeddedServers.containsKey(core != null ? core : "")) { return embeddedServers.get(core); } final EmbeddedSolrServer server = new EmbeddedSolrServer(embeddedContainer.get(), core != null ? core : ""); embeddedServers.put(core != null ? core : "", server); return server; } return getSolrClient(); }
From source file:org.springframework.data.solr.server.support.SolrClientFactoryBean.java
License:Apache License
/** * Creates an {@link EmbeddedSolrServer}. *//*from ww w.j av a2s . co m*/ private void createEmbeddedSolrServer() { try { embeddedContainer.compareAndSet(null, createEmbeddedContainer(path)); setSolrClient(new EmbeddedSolrServer(embeddedContainer.get(), core)); } catch (final Exception e) { throw new IllegalArgumentException("Unable to create embedded Solr server with path [" + path + "].", e); } }
From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java
License:Apache License
/** * @see DATASOLR-203/*w w w . j a v a 2 s. co m*/ */ @Test public void cloningEmbeddedSolrServerShouldReuseCoreContainer() { CoreContainer coreContainer = Mockito.mock(CoreContainer.class); EmbeddedSolrServer solrServer = new EmbeddedSolrServer(coreContainer, "core1"); EmbeddedSolrServer clone = SolrClientUtils.clone(solrServer, "core1"); Assert.assertThat(clone.getCoreContainer(), IsSame.sameInstance(coreContainer)); }
From source file:org.springframework.data.solr.server.support.SolrServerUtilTests.java
License:Apache License
/** * @see DATASOLR-203/* ww w .j a v a2s . co m*/ */ @Test public void cloningEmbeddedSolrServerShouldReuseCoreContainer() { CoreContainer coreContainer = Mockito.mock(CoreContainer.class); EmbeddedSolrServer solrServer = new EmbeddedSolrServer(coreContainer, null); EmbeddedSolrServer clone = SolrServerUtils.clone(solrServer, "core1"); Assert.assertThat(clone.getCoreContainer(), IsSame.sameInstance(coreContainer)); }
From source file:org.triple_brain.module.solr_search.SearchUtils.java
License:Mozilla Public License
public SolrServer getServer() { return new EmbeddedSolrServer(coreContainer, "triple_brain"); }
From source file:org.warcbase.index.IndexerReducer.java
License:Apache License
private void initEmbeddedServer(int slice) throws IOException { if (solrHome == null) { throw new IOException("Unable to find solr home setting"); }//from w w w .j a va2 s .com Path outputShardDir = new Path(fs.getHomeDirectory() + "/" + outputDir, SHARD_PREFIX + slice); LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHome + ", fs: " + fs + ", outputShardDir: " + outputShardDir); Path solrDataDir = new Path(outputShardDir, "data"); if (!fs.exists(solrDataDir) && !fs.mkdirs(solrDataDir)) { throw new IOException("Unable to create " + solrDataDir); } String dataDirStr = solrDataDir.toUri().toString(); LOG.info("Attempting to set data dir to: " + dataDirStr); System.setProperty("solr.data.dir", dataDirStr); System.setProperty("solr.home", solrHome.toString()); System.setProperty("solr.solr.home", solrHome.toString()); System.setProperty("solr.hdfs.home", outputDir.toString()); System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName()); System.setProperty("solr.lock.type", "hdfs"); System.setProperty("solr.hdfs.nrtcachingdirectory", "false"); System.setProperty("solr.hdfs.blockcache.enabled", "true"); System.setProperty("solr.hdfs.blockcache.write.enabled", "false"); System.setProperty("solr.autoCommit.maxTime", "600000"); System.setProperty("solr.autoSoftCommit.maxTime", "-1"); LOG.info("Loading the container..."); CoreContainer container = new CoreContainer(); container.load(); for (String s : container.getAllCoreNames()) { LOG.warn("Got core name: " + s); } String coreName = ""; if (container.getCoreNames().size() > 0) { coreName = container.getCoreNames().iterator().next(); } LOG.error("Now firing up the server..."); solrServer = new EmbeddedSolrServer(container, coreName); LOG.error("Server started successfully!"); }
From source file:org.wso2.carbon.registry.indexing.solr.SolrClient.java
License:Open Source License
protected SolrClient() throws IOException { // Get the solr server url from the registry.xml RegistryConfigLoader configLoader = RegistryConfigLoader.getInstance(); String solrServerUrl = configLoader.getSolrServerUrl(); // Default solr core is set to registry-indexing solrCore = IndexingConstants.DEFAULT_SOLR_SERVER_CORE; if (log.isDebugEnabled()) { log.debug("Solr server core is set as: " + solrCore); }//from www . j a va2 s. co m // Create the solr home path defined in SOLR_HOME_FILE_PATH : carbon_home/repository/conf/solr solrHome = new File(SOLR_HOME_FILE_PATH); if (!solrHome.exists() && !solrHome.mkdirs()) { throw new IOException("Solr home directory could not be created. path: " + solrHome); } // Create the configuration folder inside solr core : carbon_home/repository/conf/solr/<solrCore>/conf confDir = new File(solrHome, solrCore + File.separator + "conf"); if (!confDir.exists() && !confDir.mkdirs()) { throw new IOException("Solr conf directory could not be created! Path: " + confDir); } // Create lang directory inside conf to store language specific stop words // commons-io --> file utils langDir = new File(confDir, "lang"); if (!langDir.exists() && !langDir.mkdirs()) { throw new IOException("Solf lang directory could not be created! Path: " + langDir); } // Read the configuration file name and there destination path and stored in filePathMap readConfigurationFilePaths(); // Read the content of the files in filePathMap and copy them into destination path copyConfigurationFiles(); // Set the solr home path System.setProperty(SolrConstants.SOLR_HOME_SYSTEM_PROPERTY, solrHome.getPath()); if (solrServerUrl != null && !solrServerUrl.isEmpty()) { this.server = new HttpSolrClient(solrServerUrl); log.info("Http Sorl server initiated at: " + solrServerUrl); } else { CoreContainer coreContainer = new CoreContainer(solrHome.getPath()); coreContainer.load(); this.server = new EmbeddedSolrServer(coreContainer, solrCore); log.info("Default Embedded Solr Server Initialized"); } }
From source file:org.xwiki.platform.search.internal.SolrjSearchEngine.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . j a v a2 s . c om*/ * * @see org.xwiki.component.phase.Initializable#initialize() */ @Override public void initialize() throws InitializationException { String solrHome = ""; try { // Start embedded solr server. logger.info("Starting embedded solr server.."); if (System.getProperty(SOLR_HOME_KEY) == null) { solrHome = configuration.getProperty("search.solr.home"); System.setProperty(SOLR_HOME_KEY, solrHome); } /* Initialize the SOLR backend using an embedded server */ CoreContainer.Initializer initializer = new CoreContainer.Initializer(); coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); } catch (Exception e) { logger.error("Failed to initialize the solr embedded server with solr.solr.home [" + solrHome + "] :: " + e.getMessage()); } }
From source file:org.xwiki.platform.search.solr.internal.SolrSearchService.java
License:Open Source License
/** * {@inheritDoc}/*w w w.jav a2 s . c om*/ * * @see org.xwiki.observation.EventListener#onEvent(org.xwiki.observation.event.Event, java.lang.Object, * java.lang.Object) */ @Override public void onEvent(Event event, Object arg1, Object arg2) { try { System.setProperty("solr.solr.home", "~/code/binaries/apache-solr-3.5.0/example/solr"); /* Initialize the SOLR backend using an embedded server */ CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer container = initializer.initialize(); solrServer = new EmbeddedSolrServer(container, ""); // Delete the existing index. solrServer.deleteByQuery("*:*"); logger.info("SOLR initialized"); } catch (Exception e) { logger.error("Unable to initialize SOLR"); } }
From source file:org.xwiki.search.solr.internal.EmbeddedSolrInstance.java
License:Open Source License
@Override public void initialize() throws InitializationException { String solrHome = determineHomeDirectory(); try {//from w w w . j a va 2 s. c o m // Validate and initialize the home directory if needed. validateAndInitializeHomeDirectory(solrHome); // Start embedded Solr server. this.logger.info("Starting embedded Solr server..."); this.logger.info("Using Solr home directory: [{}]", solrHome); // Initialize the SOLR back-end using an embedded server. this.container = createCoreContainer(solrHome); // If we get here then there is at least one core found. We there are more, we use the first one. String coreName = this.container.getCores().iterator().next().getName(); this.server = new EmbeddedSolrServer(container, coreName); this.logger.info("Started embedded Solr server."); } catch (Exception e) { throw new InitializationException(String.format( "Failed to initialize the Solr embedded server with home directory set to [%s]", solrHome), e); } }