Tuesday, April 27, 2010

Liferay 5.2.3 and solr integration

I thought of writing this blog while I was trying to implement search indexing in clustered environment for liferay 5.2.3. I faced couple of problems and for resolution I had to read on way too many articles and blog to reach out to final implementation, so I though it would be nice to have everything in one place
Solr provides search indexing option for clustered Liferay environment.

version:
solr-web-5.2.0.1.war --solr plugin
Solr 1.4 --- Solr server

Follow the steps provided

1. Installing Solr

1. Solr is a standalone search engine thus it will be installed separately from liferay create a directory named solr which will be called as SOLR_HOME going forward.
2. Copy the content in solr folder from the downloaded solr installation bundle from http://lucene.apache.org/solr
3. Create an environment variable SOLR_HOME which points to the solr installation directory.
4. 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

5. Edit solrconfig.xml available at \solr\conf

${solr.data.dir:C:\TomcatA\webapps\example\solr\data}

change directory path for unix , I have given a windows path
This data folder will contain all the index files (try not to delete these index files manually if you don't get proper result after first run, reindex again)

Provide the path to a newly created directory which you want to hold the indexing data, after indexing files will be generated in this folder.


2. Deploy solr war
1. Copy solr.war to deploy folder of liferay from resource packet or download it directly from http://lucene.apache.org/solr


3. Installing the Solr Plug-in

Download plugin link

1. Update the solr-spring.xml file available at \WEB-INF\classes\META-INF

Change server URL e.g. http://{domain}:8181/solr/


2. Copy the update archive file in deploy folder of liferay

2b(IMP). Extract the file schema.xml from the plug-in. 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


3. Go to the Admin Portlet in Liferay 5.1 or Control panel in higher versions. 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.

References:

Solr > http://lucene.apache.org/solr

Liferay: Liferay.com

Tip: To check if Solr server is working perfectly hit the following URL after restart
To check if indexing is working fine check the data folder in Solr server new
index files must have formed there.

http://{domain}/{port}/solr/admin

Change Log: Changes have been made in LuceneUtil class for making it compatible to search users in control panel. If you have older version you need to delete a line and add a snippet and repackage you portalutil jar, check out the below mentioned link for changes.

For overcoming the issue in user search in control panel