/** * Registers a SolrCore descriptor in the registry using the core's name. * If returnPrev==false, the old core, if different, is closed. * @return a previous core having the same name if it existed and returnPrev==true */ public SolrCore register(SolrCore core, boolean returnPrev) { return register(core.getName(), core, returnPrev); }
import java.io.*; import org.apache.solr.core.*; import org.apache.solr.client.solrj.*; import org.apache.solr.client.solrj.embedded.*; import org.bytedeco.javacpp.*; import org.bytedeco.javacpp.annotation.*; public class SolrTest { static SolrServer createServer(String coreName) throws Exception { CoreContainer coreContainer = new CoreContainer(); CoreDescriptor discriptor = new CoreDescriptor(coreContainer, coreName, new File("/some/path/", coreName).getAbsolutePath()); SolrCore solrCore = coreContainer.create(discriptor); coreContainer.register(solrCore, false); return new EmbeddedSolrServer(coreContainer, coreName); } static class Query extends FunctionPointer { public @Name("query") String call(String string) throws Exception { createServer(string); return string; } } }
SolrCore core = coreContainer.create(coreDescriptor); coreContainer.register(coreId, core, true); return new EmbeddedSolrServer(coreContainer, coreId);
SolrCore core = coreContainer.create(coreDescriptor); coreContainer.register(coreId, core, true); return new EmbeddedSolrServer(coreContainer, coreId);
/** * Recreates a SolrCore. * While the new core is loading, requests will continue to be dispatched to * and processed by the old core * * @param name the name of the SolrCore to reload * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public void reload(String name) throws ParserConfigurationException, IOException, SAXException { SolrCore core; synchronized(cores) { core = cores.get(name); } if (core == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name ); SolrCore newCore = create(core.getCoreDescriptor()); // point all aliases to the reloaded core for (String alias : getCoreNames(core)) { if (!name.equals(alias)) { newCore.open(); register(alias, newCore, false); } } register(name, newCore, false); }
/** * registers a {@link SolrCore} to the {@link #server} managed by this * instance. Will replace an already existing {@link SolrCore} with the * same name * @param coreName the name of the {@link SolrCore} to register * @param coreDir the directory for the Core. If <code>null</code> is parsed * {@link #managedSolrDir}/coreName is used as default. */ private void registerCore(String coreName, File coreDir) { if(coreName == null){ coreName = server.getDefaultCoreName(); } if(coreDir == null){ //use the coreName as default coreDir = new File(managedSolrDir,coreName); } if(!coreDir.isDirectory()){ throw new IllegalArgumentException("The Core Directory '"+ coreDir+" for the Core '"+coreName+"' does not exist or is not an directory"); } SolrCore core; CoreDescriptor coreDescriptor = new CoreDescriptor(server, coreName, coreDir.getAbsolutePath()); core = server.create(coreDescriptor); //this will also replace an existing core with the same name server.register(coreName, core, false); server.persist(); //store the new/updated SolrCore in the solr.xml } private IndexMetadata updateCore(IndexMetadata metadata, ArchiveInputStream ais){
/** * registers a {@link SolrCore} to the {@link #server} managed by this * instance. Will replace an already existing {@link SolrCore} with the * same name * @param coreName the name of the {@link SolrCore} to register * @param coreDir the directory for the Core. If <code>null</code> is parsed * {@link #managedSolrDir}/coreName is used as default. */ private void registerCore(String coreName, File coreDir) { if(coreName == null){ coreName = server.getDefaultCoreName(); } if(coreDir == null){ //use the coreName as default coreDir = new File(managedSolrDir,coreName); } if(!coreDir.isDirectory()){ throw new IllegalArgumentException("The Core Directory '"+ coreDir+" for the Core '"+coreName+"' does not exist or is not an directory"); } SolrCore core; CoreDescriptor coreDescriptor = new CoreDescriptor(server, coreName, coreDir.getAbsolutePath()); core = server.create(coreDescriptor); //this will also replace an existing core with the same name server.register(coreName, core, false); server.persist(); //store the new/updated SolrCore in the solr.xml } private IndexMetadata updateCore(IndexMetadata metadata, ArchiveInputStream ais){
container.register(core, false);
/** * Constructor. Prepares solr connection. * * @param solrDir * The directory of the solr instance. * @param dataDir * The directory of the solr index data. */ public static SolrServer newEmbeddedInstance(File solrDir, File dataDir) throws SolrServerException { try { final CoreContainer cc = new CoreContainer(solrDir.getAbsolutePath()); SolrConfig config = new OpencastSolrConfig(solrDir.getAbsolutePath(), SolrConfig.DEFAULT_CONF_FILE, null); IndexSchema schema = new IndexSchema(config, solrDir + "/conf/schema.xml", null); SolrCore core0 = new SolrCore(null, dataDir.getAbsolutePath(), config, schema, null); cc.register("core0", core0, false); return new EmbeddedSolrServerWrapper(cc, "core0"); } catch (Exception e) { throw new SolrServerException(e); } }
/** * Handle "ALIAS" action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. */ protected boolean handleAliasAction(SolrQueryRequest req, SolrQueryResponse rsp) { SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.OTHER); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; if (cname.equals(name)) return doPersist; SolrCore core = coreContainer.getCore(cname); if (core != null) { doPersist = coreContainer.isPersistent(); coreContainer.register(name, core, false); // no core.close() since each entry in the cores map should increase the ref } return doPersist; }
IndexSchema indexSchema = new IndexSchema(solrConfig, instanceDir+"/conf/schema.xml", null); core = new SolrCore( null, dataDir, solrConfig, indexSchema, dcore); cores.register("", core, false); parser = new SolrRequestParsers( solrConfig );
/** * Handle "RENAME" Action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. * * @throws SolrException */ protected boolean handleRenameAction(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException { SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.OTHER); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; if (cname.equals(name)) return doPersist; SolrCore core = coreContainer.getCore(cname); if (core != null) { doPersist = coreContainer.isPersistent(); coreContainer.register(name, core, false); coreContainer.remove(cname); core.close(); } return doPersist; }
solrServerRef.getIndex()); this.core = cc.create(cd); cc.register(core, false); server = new EmbeddedSolrServer(cc, "dummy"); log.info(" ... initialised existing SolrCore at {}",solrServerRef.getIndex());
abortOnConfigurationError = cfg.getBool( "abortOnConfigurationError", abortOnConfigurationError); cores.register("", singlecore, false); cores.setPersistent(false); solrConfigFilename = cfg.getName();
@Override public CoreContainer initialize() { CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor dcore = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstanceDir()); dcore.setConfigName(solrConfig.getResourceName()); dcore.setSchemaName(indexSchema.getResourceName()); SolrCore core = new SolrCore( null, dataDirectory, solrConfig, indexSchema, dcore); container.register(coreName, core, false); return container; } }
/** * Start up an embedded Solr server. * * @param home The path to the Solr home directory * @return EmbeddedSolrServer: The instantiated server * @throws Exception if any errors occur */ private EmbeddedSolrServer startSolr(String home) throws Exception { try { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader( SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor); solrContainer.register("cheese", solrCore, false); // CoreAdminRequest.create return new EmbeddedSolrServer(solrContainer, "cheese"); } catch(Exception ex) { log.error("\nFailed to start Solr server\n"); throw ex; } }
/** * Start up an embedded Solr server. * * @param home The path to the Solr home directory * @return EmbeddedSolrServer: The instantiated server * @throws Exception if any errors occur */ private EmbeddedSolrServer startSolr(String home) throws Exception { try { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader( SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor); solrContainer.register("cheese", solrCore, false); // CoreAdminRequest.create return new EmbeddedSolrServer(solrContainer, "cheese"); } catch(Exception ex) { log.error("\nFailed to start Solr server\n"); throw ex; } }
private EmbeddedSolrServer buildSolrIndex(String home) throws ParserConfigurationException, IOException, SAXException { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader( SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); SolrCore solrCore = new SolrCore(null, solrConfig.getDataDir(),solrConfig, schema, descriptor); solrContainer.register("cheese", solrCore, false); return new EmbeddedSolrServer(solrContainer, "cheese"); }
private EmbeddedSolrServer buildSolrIndex(String home) throws ParserConfigurationException, IOException, SAXException { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader( SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); SolrCore solrCore = new SolrCore(null, solrConfig.getDataDir(),solrConfig, schema, descriptor); solrContainer.register("cheese", solrCore, false); return new EmbeddedSolrServer(solrContainer, "cheese"); }
coreContainer.register(name, core, false); rsp.add("core", core.getName()); return coreContainer.isPersistent();