简体   繁体   中英

Solr: I know solr is written in java, how do I create and control a running instance from within java, rather than running it as a separate process?

I want to access solr from within java programmatically, rather than using it as a separate service I pass http requests to. Is there a way to spin up and access it directly from java, rather than using it as a standalone service?

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

And for some reason I get the feeling that my entire question is misguided here, this is all new territory for me, thanks! Any orientation would be appreciated.

Solr recommends using the HTTP interface, as it's the best supported method of using it.

However, if you want to do what you want to do, it's called embedding, and it is possible with the Solrj client library, by 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, "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM