Thanks ryan, Works like a charm. This is roughly how I ended up doing.
QP SolrConfig solrConfig = new SolrConfig(SOLR_HOME, CONFIG_FILENAME, null); IndexSchema indexSchema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateInstanceDir())); CoreDescriptor dcore = new CoreDescriptor(container, "", solrConfig.getResourceLoader().getInstanceDir()); dcore.setConfigName(solrConfig.getResourceName()); dcore.setSchemaName(indexSchema.getResourceName()); SolrCore core = new SolrCore( null, SOLR_DATA, solrConfig, indexSchema, dcore); container.register("", core, false); SolrServer server = new EmbeddedSolrServer(container, ""); ryantxu wrote: > > > On Jan 9, 2009, at 8:12 PM, qp19 wrote: > >> >> Please bear with me. I am new to Solr. I have searched all the >> existing posts >> about this and could not find an answer. I wanted to know how do I >> go about >> creating a >> >> SolrServer using EmbeddedSolrServer. I tried to initialize this >> several ways >> but was unsuccesful. I do not have multi-core. I am using solrj 1.3. I >> attempted to use the >> >> depracated methods as mentioned in the SolrJ documentation the >> following way >> but it fails as well with unable to locate Core. >> >> >> SolrCore core = SolrCore.getSolrCore(); > > This function is deprecated and *really* should no be used -- > especially for embedded solr server. (the only chance you would have > for it to work is if you start up solr in a web app before calling this) > >> >> SolrServer server = new EmbeddedSolrServer( core ); >> > > Core initialization is kind of a mess, but this contains everything > you would need: > > CoreContainer container = new CoreContainer(new > SolrResourceLoader(SolrResourceLoader.locateInstanceDir())); > 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); > > > >> So far my installation is pretty basic with Solr running on Tomcat >> as per >> instructions in the wiki. My solr home is outside of webapps folder >> i.e >> "c:/tomcat-solr/solr". I am >> >> able to connect using CommonsHttpSolrServer("http://localhost:8080/solr >> ") >> without a problem. The question in a nutshell is, how do I instantiate >> EmbeddedSolrServer using new EmbeddedSolrServer(CoreContainer >> coreContainer, String coreName) ? Initializing CoreContainer appears >> to be >> complicated when compared to SolrCore.getSolrCore() as per the >> examples. Is >> there a simpler way to Initialize CoreContainer? Is a core(or >> CoreName) >> necessary eventhough I don't use multi-core? Also, is it possible to >> initialize EmbeddedSolrServer using spring? Thanks in advance for >> the help. >> > > yes, I use this: > > > <bean id="multiCore" class="org.apache.solr.core.CoreContainer"> > <constructor-arg><value>${dir}</value></constructor-arg> > <constructor-arg><value>${dconfigFile}</value></constructor-arg> > </bean> > > <bean id="solrFlat" > class="org.apache.solr.client.solrj.embedded.EmbeddedSolrServer"> > <constructor-arg ref="multiCore" /> > <constructor-arg value="flat" /> > </bean> > > <bean id="solrSuggest" > class="org.apache.solr.client.solrj.embedded.EmbeddedSolrServer"> > <constructor-arg ref="multiCore" /> > <constructor-arg value="suggest" /> > </bean> > > > ryan > > -- View this message in context: http://www.nabble.com/EmbeddedSolrServer-in-Single-Core-tp21383525p21490222.html Sent from the Solr - User mailing list archive at Nabble.com.