Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Integrate Solr with Liferay portal

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

solr-web-6.0.0.1.war

or

solr-web-6.0.1.1.war

• 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.

Related Articles #

Pluggable Enterprise Search with Solr

1 Attachment
90518 Views
Average (3 Votes)
The average rating is 5.0 stars out of 5.
Comments
Threaded Replies Author Date
. Note that Liferay portal version must be 5.3... Arvind Mishra December 8, 2009 2:11 PM
It has been changed to "6.0 or above" so I... Thomas Kellerer February 2, 2010 1:58 AM
I worked on using solr as Search engine in... Rishi Dev Gupta February 7, 2010 11:22 PM
Hi, I am very interested on how you... Dominique Béjean December 16, 2010 7:07 AM
I have some problems with SOLR 3.2... Bartlomiej Knabel June 22, 2011 6:50 AM
So is it that these steps won't work for... Madhu Yadav February 24, 2010 5:52 AM
Madhu, solr-web-6.0.1.1.war is availble and it... Anonymous May 21, 2010 9:39 AM
Your link to the intranet book (Liferay Portal... Juan Fernández December 10, 2009 7:53 AM
Followed instructions to the dot. Able to start... Nischala Kale January 21, 2010 5:58 PM
I am using Liferay 6.0.5 with solr-web-6.0.5.1,... Ravi Kumar Gupta October 16, 2010 10:44 PM
I am sorry if I was wrong, its true that I can... Ravi Kumar Gupta October 16, 2010 10:56 PM
Okay one more thing, I reindexed all search... Ravi Kumar Gupta October 16, 2010 11:48 PM
solr-web-6.0.0.1.war is not working with... Ravi Kumar Gupta October 19, 2010 8:24 PM
Hi Ravi, I am having same issue. When i reindex... Rajender Reddy Nagulapalle February 23, 2014 2:16 PM
With Solr 141, Tomcat-6.0.29+Liferay 6.0ee... Lulu Liu August 16, 2011 11:47 PM
So will this work for 5.2.3 as well? The... Namrata Hangal May 8, 2012 3:33 AM
A quick question - To ascertain that solr has... Namrata Hangal May 23, 2012 9:02 PM
I followed all the steps above mentioned but I... Debasis Padhi September 17, 2012 12:30 AM
Hi, I followed the steps you mentioned. I can... Mahesh Narke December 4, 2013 12:03 AM
I am unable to download solr-web-6.0.0.1.war or... Kashif Ayyaz Haider December 19, 2013 3:32 AM
You can download it from the Liferay market... Mahesh Narke December 19, 2013 10:00 PM

. Note that Liferay portal version must be 5.3 or above.
I guess it should be version 5.2.3
Posted on 12/8/09 2:11 PM.
Your link to the intranet book (Liferay Portal 5.3 Enterprise Intranets) points to "Liferay Portal 5,2 Systems Development"... this is a bit confusing
Regards
Posted on 12/10/09 7:53 AM.
Followed instructions to the dot. Able to start the Solr Server and Liferay Tomcat; There are no errors, but the Liferay installation still appears to use Lucene - calls are not being logged by the Solr Server, instead, it is rebuilding the Lucene indexes (data\lucene folder is being recreated).

Double-checked solr-spring.xml - it is pointing to the Solr Server instance; in fact, I replaced the file in my solr war file. The war file does get deployed (after copying to LiferayHome/Deploy); also tried using Plugin Installer portlet to no avail.

I tried with solr-web-5.3.0.1.war, and also using solr-web-5.2.0.1.war.

Any pointers as to what is going wrong?

Thanks!
Posted on 1/21/10 5:58 PM.
It has been changed to "6.0 or above" so I guess the initial "5.3 or above" was correct.

In a nutshell: it does not seem to be possible with a released version - at least that's the way I read this statement
Posted on 2/2/10 1:58 AM in reply to Arvind Mishra.
I worked on using solr as Search engine in order to replace the existing Liferay search portlet.

It was sometime mid last of 2009, What I did was I deployed solr was with Jboss and on top SolrJ (client for Solr) created the interface using REST api. Now whenever any CRUd is done through my custom portlets the information is stored/indexed in Solr database. The I changed the default behaviour of Search portlet so that every search request should fetch data from Solr database only.

But this article is really good to fully integarate Solr with Liferay Stack.
Posted on 2/7/10 11:22 PM in reply to Thomas Kellerer.
So is it that these steps won't work for 5.2.3+?
When is 6.0 being released?
Posted on 2/24/10 5:52 AM in reply to Thomas Kellerer.
Madhu,
solr-web-6.0.1.1.war is availble and it is working with liferay 6.0.1.

Brian Ko
Posted on 5/21/10 9:39 AM in reply to Madhu Yadav.
I am using Liferay 6.0.5 with solr-web-6.0.5.1, It seems that Solr is running fine but Liferay doesn't seem to use solr, since lucene folder is being created and cant see any changes in the solr directory.

Please help
Posted on 10/16/10 10:44 PM.
I am sorry if I was wrong, its true that I can not see any activity to Solr directory. And if I delete lucene, its re created.

But if I stop solr server, and try to reindex all search indexes, Liferay is throwing exceptions, it seems to find solr and when it doesnt get it, says, java.net.connectexception.. seems like Liferay is using Solr, but then where does solr keep all the indexes.. and why liferay has to keep lucene directory... please answer..
Posted on 10/16/10 10:56 PM in reply to ravi kumar gupta.
Okay one more thing, I reindexed all search indexes. After that I searched for some keywords in Solr Admin and I got results. This means, its working fine. Solr is running and liferay is using it..

Regards
Posted on 10/16/10 11:48 PM in reply to ravi kumar gupta.
solr-web-6.0.0.1.war is not working with Liferay 6.0.1 CE but solr-web-6.0.5.1 works fine with both LR 6.0.5 and 6.0.1 CE.

emoticon
Posted on 10/19/10 8:24 PM in reply to ravi kumar gupta.
Hi,

I am very interested on how you implemented direct search into solr with solrj an more particulary how you deal with security and also how you rebuild the url to documents.

Is it possible to have more information ?

Thank you
Posted on 12/16/10 7:07 AM in reply to Rishi Dev Gupta.
I have some problems with SOLR 3.2
http://www.liferay.com/community/forums/-/message_boards/message/9533736
Posted on 6/22/11 6:50 AM in reply to Dominique Béjean.
Lulu Liu
With Solr 141, Tomcat-6.0.29+Liferay 6.0ee bundle, I had to change solr.xml to

<?xml version="1.0" encoding="utf-8"?>

<Context docBase="$SOLR_HOME/example/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"/>

</Context>
Lulu
Posted on 8/16/11 11:47 PM.
So will this work for 5.2.3 as well? The article reads 6.0+ and some of us are still not sure...
Posted on 5/8/12 3:33 AM in reply to Lulu Liu.
A quick question -
To ascertain that solr has been used for indexing, is it necessary to see the SolrIndexer (if there is anything like that?) in liferay's console instead of LuceneIndexer?
I'm trying to integrate solr 1.4.1 with liferay 6.1 on jboss 5.1
Posted on 5/23/12 9:02 PM.
I followed all the steps above mentioned but I don't know why I got the following exception:

ERROR: cannot set an index-time boost

Is there is any other settings for this which I have to do ?
Posted on 9/17/12 12:30 AM.
Hi,
I followed the steps you mentioned. I can successfully run solr and liferay..Made changes in solr-spring file also.
But when i try to reindex , it say
Reindexing lucene started...
Can you tell me where i am possibly wrong?
Posted on 12/4/13 12:03 AM.
I am unable to download solr-web-6.0.0.1.war or solr-web-6.0.1.1.war, please provide updated link
Posted on 12/19/13 3:32 AM.
You can download it from the Liferay market place. Check portlet for your Liferay version.
https://www.liferay.com/marketplace/-/mp/application/15193648.
Posted on 12/19/13 10:00 PM in reply to Kashif Ayyaz Haider.
Hi Ravi,
I am having same issue. When i reindex its still using lucene but when i search using search portlet its trying to find through solr. Do you know how to fix this issue. I am using Liferay 6.1.1CE GA2, solr 1.4.1 and solr plugin solr-web-6.1.0.1-ce-ga1-20120106155615760.war
Posted on 2/23/14 2:16 PM in reply to ravi kumar gupta.