Solr: I know solr is written in java, how do I create and manage a running instance from java and not start it as a separate process?

I want to access solr from java programmatically and not use it as a separate service to which I pass HTTP requests. Is there a way to deploy and access it directly from java, instead of using it as a standalone service?

If this is not possible, I would like the package to be configured along with my application so that the end user does not have to have solr installed on their system beforehand. I am trying to use solr app but not install it separately, however it is possible.

And for some reason I have a feeling that my whole question here is wrong, for me this is new territory, thanks! Any orientation would be appreciated.

+3


source to share


1 answer


Solr recommends using the HTTP interface as it is the best supported way to use it.

However, if you want to do what you want, it is called nesting and this is possible with Solrj , using EmbeddedSolrServer

which will allow you to run an embedded Solr instance in your code.



A code snippet showing the use of the embedded server is also on the Solrj page :

// Note that the following property could be set through JVM level arguments too
  System.setProperty("solr.solr.home", "/path-to-solr");
  CoreContainer.Initializer initializer = new CoreContainer.Initializer();
  CoreContainer coreContainer = initializer.initialize();
  EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "");

      

+4


source







All Articles