Pluggable Enterprise Search with Solr
Table of Contents [-]
Using a Solr Server for Liferay Search #
Since Solr is a standalone search engine, you will need to download it and install it first according to the instructions on the Solr web site ([http://lucene.apache.org/solr]). Once you have Solr up and running, integrating it with Liferay is easy, but it will require a restart of your application server.
Installing Solr #
The first thing you will need to define is the location of your search index. Assuming you are running a Linux server and you have mounted a file system for the index at /solr, create an environment variable that points to this folder. This environment variable needs to be called $SOLR_HOME. So for our example, we would define:
$SOLR_HOME=/solr
This environment variable can be defined anywhere you need: in your operating system's start up sequence, in the environment for the user who is logged in, or in the start up script for your application server. If you are going to use Tomcat to host Solr, you would modify catalina.sh or catalina.bat and add the environment variable there.
Once you have created the environment variable, you then can use it in your application server's start up configuration as a parameter to your JVM. This is configured differently per application server, but again, if you are using Tomcat, you would edit catalina.sh or catalina.bat and append the following to the $JAVA_OPTS variable:
-Dsolr.solr.home=$SOLR_HOME
This takes care of telling Solr where to store its search index.
Installing the Solr Plugin #
Next, you have a choice. If you have installed Solr on the same system upon which Liferay is running, you can simply go to a Plugin Installer portlet and install the solr-web plugin. Of course, if you are doing this for a clustered environment, it is likely that you are not running Liferay and your search engine on the same box, so you will have to make a change to a configuration file in the plugin before you install it. In this case, go to the Liferay web site (http://www.liferay.com) and download the plugin manually.
Open or extract the plugin. Inside the plugin, you will find a file called solr-spring.xml in the WEB-INF/classes/META-INF folder. Open this file in a text editor and you will see that there are two entries which define where the Solr server can be found by Liferay:
<bean id="indexSearcher" class="com.liferay.portal.search.solr.SolrIndexSearcherImpl">
<property name="serverURL" value="http://localhost:8080/solr/select" />
</bean>
<bean id="indexWriter" class="com.liferay.portal.search.solr.SolrIndexWriterImpl">
<property name="serverURL" value="http://localhost:8080/solr/update" />
</bean>Modify these values so that they point to the server upon which you are running Solr. Then save the file and put it back into the plugin archive in the same place it was before.
Next, extract the file schema.xml from the plugin. This xml file describes how the fields will be indexed to the Solr index and it should be located in the docroot/WEB-INF/conf folder. Copy this file to $SOLR_HOME/conf (you may have to create the conf directory). Now go ahead and start the application server upon which you are going to install Solr. This can be the same server Liferay is running on or a completely different box (a separate box for your search server will give you better performance). Install the Solr .war file to this application server.
You can now hot deploy the solr-web plugin to all of your nodes.
Once the plugin is hot deployed, your Liferay search is automatically upgraded to use Solr. It is likely, however, that initial searches will come up with nothing: this is because you will need to reindex everything using Solr.
Go to the Admin Portlet. Click the Server tab and then click the Execute button next to Reindex all search indexes. It may take a while, but Liferay will begin sending indexing requests to Solr for execution. When the process is complete, Solr will have a complete search index of your site, and will be running independently of all of your Liferay nodes.
Installing the plugin to your nodes has the effect of overriding any calls to Lucene for searching. All of Liferay's search boxes will now use Solr as the search index. This is ideal for a clustered environment, as it allows all of your nodes to share one search server and one search index, and this search server operates independently of all of your nodes.