
Integrate Solr with Liferay portal
Table of Contents [-]
Introduction #
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.
This article shows how to integrate Solr within Liferay Portal. Note that Liferay portal version must be 6 or above.
And moreover, this article is abstracted from the book: Liferay Portal 6 Enterprise Intranets
Install Solr Instance #
In five steps, you could install the Solr example as an instance under Tomcat. Of course, you can find similar installation processes for JBoss, Jetty, Resin, WebSphere, Weblogic, etc.
• Download the latest version of Solr from http://lucene.apache.org/solr/ install it and mark the root of installation folder as the variable $SOLR_HOME.
• Copy the WAR file $SOLR_HOME/dist/apache-solr-${solr.version}.war into $SOLR_HOME/example; where ${solr.version} represents Solr version number, i.e., 1.4.0 or 3.3.0.
• Create a Tomcat Context fragment called solr.xml with following lines.
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="$SOLR_HOME/example/apache-solr-${solr.version}.war" debug="0" crossContext="true"><Environment name="solr/home" type="java.lang.String" value="$SOLR_HOME/example" override="true"/> </Context>}}}
• Drop the file solr.xml into the folder $TOMCAT_AS_DIR/conf/Catalina/localhost
• Add following line at the end of $TOMCAT_AS_DIR/bin/setenv.sh for Linux or MacOS as follows. JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=$SOLR_HOME/example/solr/data" Or add following line at the end of $TOMCAT_AS_DIR/bin/setenv.bat for Windows as follows; set JAVA_OPTS=%JAVA_OPTS% -Dsolr.solr.home=$SOLR_HOME/example/solr/data
• You may have to move up the "bin" and "conf" folders from $SOLR_HOME/example/solr/ to $SOLR_HOME/example.
Repeat the above steps with different installation directories to run multiple instances of Solr side-by-side. Starting Tomcat, the Solr admin should be available at http://${solr.host.domain}:${solr.port.number}/solr/admin, where ${solr.host.domain} represents Solr instance domain name, like locahost; ${solr.port.number} represents Solr instance port; number, like 8080.
Configure Solr plugin #
Once the Solr instance was set, you can install the Solr plugin in the portal. How does it work? The following is a sample which could bring the plugin Solr into the portal.
• Download WAR file ${solr.web.war} from
or
• Drop the WAR file ${solr.web.war} to the folder $LIFERAY_HOME/deploy when the portal is running.
After deploying successfully, you should shut down the portal and Solr instance, and moreover, configure the Solr instance with the Solr plugin as follows.
• Open $AS_WEB_APP_HOME/solr-web/WEB-INF/classes/META-INF/solr-spring.xml and update Solr instance settings as follows.
<bean id="solrServer" class="com.liferay.portal.search.solr.server.BasicAuthSolrServer"><constructor-arg type="java.lang.String" value=" http://${solr.host.domain}:${solr.port.number}/solr" /> </bean>}}}
• Drop the schema file schema.xml from $AS_WEB_APP_HOME/solr-web/WEB-INF/conf to $SOLR_HOME/example/solr/conf in the domain ${solr.host.domain} – replacing the exiting the schema file schema.xml; and restart Solr instance and the portal.
• Change library from your downloaded version of solr otherwise this plugin only index the data but not search any. If you using solr3.1 get solr library and change the plugin's $AS_WEB_APP_HOME/solr-web/WEB-INF/lib delete first
solr-common.jar
solr-solrj.jar
then add your current versions solr library for example
apache-solr-solrj-3.1.0.jar or
apache-solr-solrj-3.3.0.jar
High Availability #
Please see the attachments section for an overview of how to ensure high availability with SOLR. This is a general overview, which will give you the idea of how to setup your network to support a stable search environment in Liferay.