List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
From source file:org.schedoscope.metascope.index.SolrFacade.java
License:Apache License
@PostConstruct public void init() { if (solrClient == null) { String url = solrUrl;// w ww .j ava2s.c o m if (url.startsWith(SOLR_HTTP_PREFIX)) { initSolrFacade(new HttpSolrClient(url)); } else { CoreContainer coreContainer = new CoreContainer(url); coreContainer.load(); initSolrFacade(new EmbeddedSolrServer(coreContainer, METASCOPE_CORE)); } } }
From source file:org.shanghai.rdf.SolrPost.java
License:Apache License
public void create() { if (solr.startsWith("http://")) { server = new HttpSolrServer(solr); } else if (solr.startsWith("/")) { String solrDir = solr.substring(0, solr.lastIndexOf("/")); String core = solr.substring(solr.lastIndexOf("/") + 1); log("solr emb " + solrDir + " core " + core); CoreContainer container = new CoreContainer(solrDir); container.load(solrDir, new File("solr.xml")); server = new EmbeddedSolrServer(container, core); }// w w w .ja va 2s .com }
From source file:org.si4t.solr.SolrIndexDispatcher.java
License:Apache License
/** * Creates the embedded solr server.//from w w w . ja v a 2 s. c om * * Use this only in special cases to for instance to first time indexing. * * @deprecated * @param searcherId * @param solrHome * @param coreName * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ @Deprecated private void createEmbeddedSolrServer(String searcherId, String solrHome, String coreName) throws ParserConfigurationException, IOException, SAXException { File home = new File(solrHome); File solrConfig = new File(home, "solr.xml"); // Solr 4.4.0 change CoreContainer coreContainer = CoreContainer.createAndLoad(solrHome, solrConfig); EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); _solrServers.put(searcherId, server); _solrContainers.put(searcherId, coreContainer); log.info("Created an Embedded Solr server client instance for " + searcherId + ", " + solrHome + ", " + coreName); }
From source file:org.sindice.siren.solr.SolrServerWrapper.java
License:Apache License
public SolrServerWrapper(final String solrHome) throws IOException, ParserConfigurationException, SAXException { this.solrHome = solrHome; System.setProperty("solr.solr.home", solrHome); final CoreContainer.Initializer initializer = new CoreContainer.Initializer(); coreContainer = initializer.initialize(); server = new EmbeddedSolrServer(coreContainer, ""); }
From source file:org.sparkcommerce.core.search.service.solr.SolrSearchServiceImpl.java
License:Apache License
public SolrSearchServiceImpl(String solrServer) throws IOException, ParserConfigurationException, SAXException { if ("solrhome".equals(solrServer)) { final String baseTempPath = System.getProperty("java.io.tmpdir"); File tempDir = new File( baseTempPath + File.separator + System.getProperty("user.name") + File.separator + "solrhome"); if (System.getProperty("tmpdir.solrhome") != null) { //allow for an override of tmpdir tempDir = new File(System.getProperty("tmpdir.solrhome")); }/*w w w .ja va2 s. c om*/ if (!tempDir.exists()) { tempDir.mkdirs(); } solrServer = tempDir.getAbsolutePath(); // create the 'lib' directory with a placeholder file that has to exist in Solr's home directory to avoid a // warning log message String libDir = FilenameUtils.concat(solrServer, "lib"); LOG.debug("Creating Solr home lib directory: " + libDir); new File(libDir).mkdir(); String placeholder = FilenameUtils.concat(libDir, "solrlib_placeholder.deleteme"); LOG.debug("Creating Solr lib placeholder file: " + placeholder); new File(placeholder).createNewFile(); } File solrXml = new File(new File(solrServer), "solr.xml"); if (!solrXml.exists()) { copyConfigToSolrHome(this.getClass().getResourceAsStream("/solr-default.xml"), solrXml); } LOG.debug(String.format("Using [%s] as solrhome", solrServer)); LOG.debug(String.format("Using [%s] as solr.xml", solrXml.getAbsoluteFile())); if (LOG.isTraceEnabled()) { LOG.trace("Contents of solr.xml:"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(solrXml)); String line; while ((line = br.readLine()) != null) { LOG.trace(line); } } finally { if (br != null) { try { br.close(); } catch (Throwable e) { //do nothing } } } LOG.trace("Done printing solr.xml"); } CoreContainer coreContainer = CoreContainer.createAndLoad(solrServer, solrXml); EmbeddedSolrServer primaryServer = new EmbeddedSolrServer(coreContainer, SolrContext.PRIMARY); EmbeddedSolrServer reindexServer = new EmbeddedSolrServer(coreContainer, SolrContext.REINDEX); SolrContext.setPrimaryServer(primaryServer); SolrContext.setReindexServer(reindexServer); //NOTE: There is no reason to set the admin server here as the SolrContext will return the primary server //if the admin server is not set... }
From source file:org.springframework.data.search.solr.SolrTemplate.java
License:Apache License
/** * Initializes a Solr server based on basic configuration information * available for the Solr server./*from w ww . ja va2 s. c o m*/ * * @param core The name of the Solr core to use. * @param embedded If <code>true</code>, an {@link EmbeddedSolrServer} * instance is created. * @param paths Paths to the Solr server. If <code>embedded</code> is * <code>true</code>, this should contain exactly one path. A * {@link RuntimeException} will be thrown if * <code>embedded</code> is <code>true</code> and this parameter * has more than one path. If <code>embedded</code> is * <code>false</code>, this can contain one or more paths. A * {@link CommonsHttpSolrServer} instance is created if only one * path is passed, otherwise an {@link LBHttpSolrServer} instance * is created with all the paths. * @throws IOException If no Solr configuration can be found at the location * pointed to by <code>path</code>. * @throws MalformedURLException If any of the <code>paths</code> values is * malformed. * @throws ParserConfigurationException If the Solr configuration at any of * the locations pointed to by <code>paths</code> cannot be * parsed correctly. * @throws SAXException If the Solr configuration at any of the locations * pointed to by <code>paths</code> contains invalid XML. */ private static SolrServer createSolrServer(final String core, final boolean embedded, final String[] paths) throws IOException, MalformedURLException, ParserConfigurationException, SAXException { if (paths == null) { throw new RuntimeException("Argument [paths] is null."); } else if (paths[0] == null) { throw new RuntimeException("Argument [paths] contains a null path."); } else if (paths[0].trim().equals("")) { throw new RuntimeException("Argument [paths] contains a blank path."); } if (embedded) { if (paths.length > 1) { throw new RuntimeException( "Argument [embedded] is set to [true] but the argument [paths] contains more than one path."); } else if (core == null) { throw new RuntimeException( "Argument [embedded] is set to [true] but the argument [coreName] contains a null value."); } else if (core.trim().equals("")) { throw new RuntimeException( "Argument [embedded] is set to [true] but the argument [coreName] contains a blank value."); } else { final File configFile = new ClassPathResource(paths[0].trim()).getFile(); final CoreContainer coreContainer = new CoreContainer(); coreContainer.load(configFile.getParentFile().getAbsolutePath(), configFile); return new EmbeddedSolrServer(coreContainer, core); } } else if (paths.length > 1) { return new LBHttpSolrServer(paths); } return new CommonsHttpSolrServer(PathUtil.concatenate('/', paths[0], core)); }
From source file:org.springframework.data.solr.AbstractITestWithEmbeddedSolrServer.java
License:Apache License
@BeforeClass public static void initSolrServer() throws IOException, ParserConfigurationException, SAXException, InterruptedException { String solrHome = ResourceUtils.getURL("classpath:org/springframework/data/solr").getPath(); CoreContainer coreContainer = CoreContainer.createAndLoad(solrHome, new File(solrHome + "/solr.xml")); for (SolrCore core : coreContainer.getCores()) { core.addCloseHook(new CloseHook() { @Override/*from w ww . j av a2 s .co m*/ public void preClose(SolrCore core) { } @Override public void postClose(SolrCore core) { CoreDescriptor cd = core.getCoreDescriptor(); if (cd != null) { File dataDir = new File(cd.getInstanceDir() + File.separator + "data"); try { FileUtils.deleteDirectory(dataDir); } catch (IOException e) { e.printStackTrace(); } } } }); } solrServer = new EmbeddedSolrServer(coreContainer, "collection1"); }
From source file:org.springframework.data.solr.embedded.EmbeddedSolrServerFactory.java
License:Apache License
/** * @param path Any Path expression valid for use with {@link ResourceUtils} * @return new instance of {@link EmbeddedSolrServer} * @throws ParserConfigurationException/* www .j ava 2s .c o m*/ * @throws IOException * @throws SAXException */ public final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException { String solrHome = System.getProperty(SOLR_HOME_SYSTEM_PROPERTY); if (StringUtils.isBlank(solrHome)) { solrHome = ResourceUtils.getURL(path).getPath(); } return new EmbeddedSolrServer(new CoreContainer(solrHome, new File(solrHome + "/solr.xml")), null); }
From source file:org.springframework.data.solr.repository.cdi.SolrTemplateProducer.java
License:Apache License
private SolrServer getSolrServerInstance() throws IOException, ParserConfigurationException, SAXException { System.setProperty("solr.solr.home", ResourceUtils.getURL("classpath:org/springframework/data/solr").getPath()); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); return new EmbeddedSolrServer(coreContainer, ""); }
From source file:org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.java
License:Apache License
/** * @param path Any Path expression valid for use with {@link ResourceUtils} * @return new instance of {@link EmbeddedSolrServer} * @throws ParserConfigurationException/* w ww . j av a2 s . c o m*/ * @throws IOException * @throws SAXException */ public final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException { String solrHomeDirectory = System.getProperty(SOLR_HOME_SYSTEM_PROPERTY); if (StringUtils.isBlank(solrHomeDirectory)) { solrHomeDirectory = ResourceUtils.getURL(path).getPath(); } solrHomeDirectory = URLDecoder.decode(solrHomeDirectory, "utf-8"); return new EmbeddedSolrServer(createCoreContainer(solrHomeDirectory), null); }