Search code examples
javasolrsolrj

Integration of Solr with existing web application


I know that there were other questions regarding this topic and I read some tutorials on the web (http://shrutiags.wordpress.com/2012/05/29/adding-solr-to-your-web-application-part-3-integrating-solr-with-eclipse-2/ and http://javaskeleton.blogspot.de/2011/07/adding-solr-to-existing-web-application.html). I still have some unresolved questions.

1) Both mentioned tutorials use EmbeddedSolrServer to access Solr, does it mean that Solr is not run as a separate application? Why do we need to specify filters and servlets then?

2) Both tutorials use copy and paste of jars. What are the maven dependencies that one should use instead?

3) I'm still not sure about differences between embedded and standalone way to integrate Solr into existing web app. As I understood, standalone way means to deploy Solr war file as a separate application. In this case we shouldn't specify any servlets or filter and just use Solrj to connect to running instance of Solr.

What is changing when we want to run Solr as part of our app? We need to add more dependencies, not just Solrj. And we need to initialize somehow Solr core. Am I correct?


Solution

  • Responding to your questions:

    1) you do not need always to use EmbeddedSolrServer always... Solr can be deployed in an application server or servlet container as a "standalone" web service, which means you do not need to specify filters and servlets, simply deploy it somewhere (tomcat, jetty, glassfish, etc.) and define in your application a "SolrServer": SolrServer server = new CommonsHttpSolrServer(solrServerAddress); and use it to communicate with Solr.

    2) from my own setup, I have the following maven dependency to work with a standalone Solr:

    <dependency>
        <artifactId>solr-solrj</artifactId>
        <groupId>org.apache.solr</groupId>
        <version>1.4.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    

    You may need to define other dependencies (e.g.: if you want the EmbeddedSolrServer), find clear details here: http://wiki.apache.org/solr/Solrj#Maven. You also need to make sure you have slf4j in your maven dependencies.

    3) that is true, if it is a standalone, you need to take some other actions but there is not need to define any servlets or filters.

    Concerning the question: "What is changing when we want to run Solr as part of our app? We need to add more dependencies, not just Solrj." Yes you need... you can find info about that in the link above from Solr.