List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
From source file:eu.europeana.solr.SimpleCollectionSolrInstance.java
License:Apache License
/** * This method creates an in-process Solr server that otherwise behaves just * as youd expect./*from ww w .j a va 2 s . com*/ */ private synchronized SolrServer getDelegate() throws SolrServerException { if (delegate != null) { return delegate; } try { final File dir = FileUtils.getTempDirectory(); System.setProperty("solr.solr.home", dir.getAbsolutePath()); final File conf = new File(new File(solrdir, "conf"), "solrconfig.xml"); final CoreContainer cc = new CoreContainer(); final SolrConfig sc = new SolrConfig(conf.getAbsolutePath()); final CoreDescriptor cd = new CoreDescriptor(cc, CORE1, solrdir.getAbsolutePath()); core = cc.create(cd); cc.register(CORE1, core, false); delegate = new EmbeddedSolrServer(cc, CORE1); return delegate; } catch (ParserConfigurationException ex) { throw new SolrServerException(ex); } catch (SAXException ex) { throw new SolrServerException(ex); } catch (IOException ex) { throw new SolrServerException(ex); } }
From source file:eu.europeana.solr.SolrServerTester.java
License:Apache License
/** * This method creates an in-process Solr server that otherwise behaves just * as youd expect./*from w w w .ja va 2s .com*/ */ private synchronized SolrServer getDelegate() throws SolrServerException { if (delegate != null) { return delegate; } try { // File solrconfigXml = new File(new File(solrdir, "conf"), // "solrconfig.xml"); // // logger.info("solrconfig = {}",solrconfigXml); // // CoreContainer container = new CoreContainer(solrdir.getPath(), // solrconfigXml); // CoreDescriptor descriptor = new CoreDescriptor(container, // "collection1", // solrdir.getCanonicalPath()); // // core = container.create(descriptor); // container.register("collection1", core, false); // delegate = new EmbeddedSolrServer(container, "collection1"); // // return delegate; final File dir = FileUtils.getTempDirectory(); System.setProperty("solr.solr.home", dir.getAbsolutePath()); final File conf = new File(new File(solrdir, "conf"), "solrconfig.xml"); final CoreContainer cc = new CoreContainer(); final SolrConfig sc = new SolrConfig(conf.getAbsolutePath()); final CoreDescriptor cd = new CoreDescriptor(cc, CORE1, solrdir.getAbsolutePath()); core = cc.create(cd); cc.register(CORE1, core, false); delegate = new EmbeddedSolrServer(cc, CORE1); return delegate; } catch (ParserConfigurationException ex) { throw new SolrServerException(ex); } catch (SAXException ex) { throw new SolrServerException(ex); } catch (IOException ex) { throw new SolrServerException(ex); } }
From source file:fi.vm.sade.organisaatio.service.search.EmbeddedSolrServerFactory.java
License:EUPL
public SolrServer getSolrServer() { log.info("**** Using embedded Solr server ****"); if (StringUtils.isEmpty(solrHome)) { solrHome = "../organisaatio-service/src/main/resources/solr/"; }/*from w w w . j a va 2 s .c om*/ if (StringUtils.isEmpty(solrData)) { solrData = "target/solr-data"; } if (server == null) { System.setProperty("solr.solr.home", solrHome); System.setProperty("solr.data.dir", solrData); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); server = new EmbeddedSolrServer(coreContainer, "organisaatiot"); System.clearProperty("solr.solr.home"); System.clearProperty("solr.data.dir"); } return server; }
From source file:fr.cnes.sitools.metacatalogue.index.solr.SolRUtils.java
License:Open Source License
/** * /*from ww w . j av a 2 s . c o m*/ * @param solrHome * @param configFileName * @return */ public static SolrServer getEmbeddedSolRServer(String solrHome, String configFileName, String coreName) { SolrServer solrServer; File configFile = new File(solrHome + "/" + configFileName); CoreContainer coreContainer = CoreContainer.createAndLoad(solrHome, configFile); EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); solrServer = server; solrServer = checkServer(server); if (solrServer != null) { logger.info("First SolR valid connection"); } return solrServer; }
From source file:fr.gael.dhus.service.SystemService.java
License:Open Source License
/** * Performs Solr restoration.// ww w . j a v a2 s .c o m * * @param properties properties containing arguments to execute the restoration. */ private static void restoreSolr5Index(Properties properties) throws IOException, SolrServerException { String solrHome = properties.getProperty("dhus.solr.home"); String coreName = properties.getProperty("dhus.solr.core.name"); final String name = properties.getProperty("dhus.solr.backup.name"); final String location = properties.getProperty("dhus.solr.backup.location"); if (solrHome == null || coreName == null || name == null || location == null) { throw new UnsupportedOperationException(); } System.setProperty("solr.solr.home", solrHome); CoreContainer core = new CoreContainer(solrHome); EmbeddedSolrServer server = new EmbeddedSolrServer(core, coreName); try { server.getCoreContainer().load(); SolrQuery query = new SolrQuery(); query.setRequestHandler("/replication"); query.set("command", "restore"); query.set("name", name); query.set("location", location); server.query(query); LOGGER.info("SolR indexes restored."); } finally { server.close(); } }
From source file:fr.jetoile.hadoopunit.component.SolrBootstrap.java
License:Apache License
private final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException, BootstrapException { String solrHomeDirectory = path; if (System.getProperty("os.name").startsWith("Windows")) { // solrHomeDirectory = solrHomeDirectory.substring(1); }//from w ww . j a v a 2 s .c o m solrHomeDirectory = URLDecoder.decode(solrHomeDirectory, "utf-8"); return new EmbeddedSolrServer(createCoreContainer(solrHomeDirectory), solrCollectionInternalName); }
From source file:io.redlink.solrlib.embedded.EmbeddedCoreContainer.java
License:Apache License
@Override protected SolrClient createSolrClient(String coreName) { Preconditions.checkState(Objects.nonNull(coreContainer), "CoreContainer not initialized!"); Preconditions.checkArgument(StringUtils.isNotBlank(coreName)); return new EmbeddedSolrServer(coreContainer, coreName) { @Override//from www . j a va 2 s .c om public void close() throws IOException { //nop } }; }
From source file:io.vertigo.dynamo.plugins.search.solr.embedded.EmbeddedSolrSearchServicesPlugin.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w ww .j av a2s.c o m*/ protected SolrServer createSolrServer(final String core) { Assertion.checkArgument(coreContainer.getCoreNames().contains(core), "core {0} non reconnu lors du dmarrage du container", core); return new EmbeddedSolrServer(coreContainer, core); }
From source file:it.seralf.solrbook.client.java.EmbeddedSolrExample.java
License:Apache License
public static void main(String[] args) throws Exception { // NOTE: we can override this configuration, passing a valid slr home from command line System.setProperty("solr.solr.home", "solr-home"); CoreContainer container = new CoreContainer(); container.load();/*from w ww. j a va 2s. co m*/ EmbeddedSolrServer server = new EmbeddedSolrServer(container, "arts"); // delete all documents server.deleteByQuery("*:*"); Artist doc = new Artist("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", "Leonardo Da Vinci", "Vinci", "Florence"); server.addBean(doc); server.commit(); QueryResponse rsp = server.query(new SolrQuery("leonardo"), METHOD.GET); SolrDocumentList oo = rsp.getResults(); for (SolrDocument d : oo) { for (String field : d.getFieldNames()) { System.out.printf("%s = %s\n", field, d.getFieldValue(field)); } } server.shutdown(); }
From source file:jp.aegif.nemaki.NemakiCoreAdminHandler.java
License:Open Source License
public NemakiCoreAdminHandler(CoreContainer coreContainer) { super(coreContainer); PropertyManager pm = new PropertyManagerImpl(StringPool.PROPERTIES_NAME); String repositoryCorename = pm.readValue(PropertyKey.SOLR_CORE_MAIN); String tokenCoreName = pm.readValue(PropertyKey.SOLR_CORE_TOKEN); SolrServer repositoryServer = new EmbeddedSolrServer(coreContainer, repositoryCorename); SolrServer tokenServer = new EmbeddedSolrServer(coreContainer, tokenCoreName); SolrCore core = getCoreContainer().getCore(repositoryCorename); CoreTracker tracker = new CoreTracker(this, core, repositoryServer, tokenServer); logger.info("NemakiCoreAdminHandler successfully instantiated"); String jobEnabled = pm.readValue(PropertyKey.SOLR_TRACKING_CRON_ENABLED); if ("true".equals(jobEnabled)) { // Configure Job JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("ADMIN_HANDLER", this); jobDataMap.put("TRACKER", tracker); JobDetail job = newJob(CoreTrackerJob.class).withIdentity("CoreTrackerJob", "Solr") .usingJobData(jobDataMap).build(); // Configure Trigger // Cron expression is set in a property file String cron = pm.readValue(PropertyKey.SOLR_TRACKING_CRON_EXPRESSION); Trigger trigger = newTrigger().withIdentity("TrackTrigger", "Solr") .withSchedule(CronScheduleBuilder.cronSchedule(cron)).build(); // Configure Scheduler StdSchedulerFactory factory = new StdSchedulerFactory(); Properties properties = new Properties(); properties.setProperty("org.quartz.scheduler.instanceName", "NemakiSolrTrackerScheduler"); properties.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); properties.setProperty("org.quartz.threadPool.threadCount", "1"); properties.setProperty("org.quartz.threadPool.makeThreadsDaemons", "true"); properties.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", "true"); properties.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore"); // Start quartz scheduler try {//from w w w .ja v a 2 s.co m factory.initialize(properties); scheduler = factory.getScheduler(); scheduler.start(); scheduler.scheduleJob(job, trigger); } catch (SchedulerException e) { logger.error("Start quartz scheduler error:", e); } } }