Tuesday, September 17, 2013

Liferay 6.1 integration with Solr Search Engine

Liferay 6.1 integration with Solr Search Engine

Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, and rich document (e.g., Word, PDF) handling. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest internet sites. Refer to Apache Solr.

We have made enhancement to the search infrastructure of the portal recently. We abstracted out Lucene as a search engine, now people can build plugins that integrate with others search engines frameworks.

Currently the only plugin developed is one of the Solr, the Lucene plugin is the default implementation and comes bundled with the portal.
Roughly speaking, Solr is an application that listens for indexing and searching commands via HTTP requests. You can deploy Liferay in one server and have Solr running in a different server, this is very helpful for clustered portals because we got rid of racing issues when Lucene JDBC was used. Also, you can have a cluster of Solr instances that does load balancing of requests.

Use Case:  Integrate Solr Search with Liferay 6.1 in a clustered environment

·         Download Liferay 6.1 CE version from here.
·         Download solr-web- (Solr-Plugin) for Liferay 6.1 CE version
·         Download Apache Tomcat 7.0.x stable version.
·         Download Solr 1.4.1 release from here.

Configuration Steps:

Step 1: Extract the downloaded Solr 1.4.1 Zip file. I will call that extracted folder as SOLR_HOME. For e.g. consider SOLR_HOME as D:\Apache_solr\apache-solr-1.4.1

Step 2: Copy apache-solr-1.4.1.war from SOLR_HOME\dist\ to SOLR_HOME\example\solr

Step 3: Open SOLR_HOME\example\solr\conf\solrconfig.xml file and
[Note : Instead of <<SOLR_HOME>> write down the actual path]

Step 4: It is recommended to run the solr instance on separate tomcat instance other than Liferay tomcat instance.
For that extract the downloaded Apache Tomcat 7.0.x. I will call that extracted folder as SOLR_TOMCAT. For e.g. Consider SOLR_TOMCAT as D:\Apache_Tomcat\apache-tomcat-7.0.16

Step 5: Open SOLR_TOMCAT/conf/server.xml and make necessary changes
·         Change server port to 9005
<Server port="9005" shutdown="SHUTDOWN">
·         Change Connector port to 9090 and redirectPort to 9443
<Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="9443" />
·         Change AJP Connector port to 9009
<Connector port="9009" protocol="AJP/1.3" redirectPort="9443" />

Step 6: Set the following line to setenv.bat
export JAVA_OPTS="$JAVA_OPTS  -Dsolr.data.dir=<<SOLR_HOME>> /example/solr/data"
[Note: Instead of <<SOLR_HOME>> use actual path]

Step 7: Create a solr.xml under SOLR_TOMCAT\conf\Catalina\localhost\ with the following content

<?xml version="1.0" encoding="utf-8"?>
<Context docBase="<<SOLR_HOME>>/example/solr/apache-solr-1.4.1.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="<<SOLR_HOME>>/example/solr" override="true"/>
[Note: Instead of <<SOLR_HOME>> use actual path]

Step 8:  Now start tomcat server and check whether it’s running without error. If started successfully then go to browser and check http://localhost:9090/solr. (You will find SOLR Home page here)

Step 9: Integrate SOLR Plugin with Liferay server.

[Note: For this step, we have an assumption that Liferay server setup is already in your machine and its running successfully]
      ·         Deploy the downloaded solr-web- to Liferay instance
      ·         Once its deployed, stop the Liferay server and SOLR_TOMCAT
      ·         Copy Schema.xml from Liferay_HOME\tomcat\webapps\solr-web\WEB-INF\conf\ to                   SOLR_HOME\example\solr\conf\
      ·         Open Liferay_HOME\tomcat\webapps\solr-web\WEB-INF\classes\META-INF\solr-                       spring.xml and modify

<bean id="com.liferay.portal.search.solr.server.BasicAuthSolrServer" class="com.liferay.portal.search.solr.server.BasicAuthSolrServer">
  <constructor-arg type="java.lang.String" value="http://localhost:8080/solr" />

With this

      <bean id="com.liferay.portal.search.solr.server.BasicAuthSolrServer" class="com.liferay.portal.search.solr.server.BasicAuthSolrServer">
<constructor-arg type="java.lang.String" value="http://localhost:9090/solr" />

It’s done. Start SOLR_TOMCAT and Liferay server and test with OOTB Search portlet.

When you search anything on Liferay server, you will find that logs are updated on SOLR_TOMCAT console.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.