Tuesday Apr 08, 2008

Solr on Sun One Webserver

For a project that I'm messing with here at work the request has been made to add in search capabilities (along with a few other things) to it. The first choice of course is to use Lucene and beat it with a hammer to get it to work the way you want it to. I could have done this, but the application has multiple parts to it running on different machines and some of them will need to feed data in and other will make the search queries. I didn't really want to also have to write all the interfaces for the various bits and pieces to talk to the search engine. Where is the fun in that these days. Looking around a little more I found Solr which is built on top of Lucene and seems to do exactly what I want.

Anyway, to make a long story short. I wanted to run this in the Sun One Webserver since I think it's a much better platform than Tomcat. It does have it's quirks to it, but once you get to know them it's a great webserver and Servlet Container all built into one that performs so much better. So part of the Solr config is telling it where it's home directory is to store index information and find all of the config files. This can be done with a Java environment property fed into the JVM with a -D${property}=${value}, but I wanted it to be read from the Context config itself. No need to have various cruft hanging around in the server.xml file if you don't need it. You can configure a JNDI Environment value for Solr to pick up where it's home directory is. So for those that want to know how to do that I present what I added into my web.xml for the Solr web application.

<env-entry>
  <description>Solr Home</description>
  <env-entry-name>solr/home</env-entry-name>
  <env-entry-value>/www/webapps/apache-solr-1.2.0</env-entry-value>
  <env-entry-type>java.lang.String</env-entry-type>
<env-entry>

Isn't that easy? Then when Solr looks for the home directory value in it's JDNI lookup it will find it and go about it's merry way in initializing. I was doing all kinds of things with trying to setup a in a sun-web.xml and then trying to reference it over to a JNDI setting in the server.xml and all kinds of other things (since, well... it's not the best documented thing in the SWS docs), but the above was all I needed. Pretty simple actually. Now I need to go and configure the Solr schema and start feeding it information to index.

Comments:

Post a Comment:
Comments are closed for this entry.