Customizing and configuring federated search - OpenSearch - in Liferay portal

Federated search is the simultaneous search of multiple online databases or web resources, and it is an emerging feature of automated, web-based library and information retrieval systems. Here federated search is referred to the portal.

It is very useful to provide federated search abilities, such as search for Blogs entries, users, organizations,  Calendar entries, Bookmarks entries, Document Library documents, Image Gallery images, Message Boards message, Wiki articles, Web Content articles, Directory, etc. The portal has provides a set of search portlets. In this section, we’re going to have a deep look on these portlets.

Abstracted from the book: Liferay Portal 6 Enterprise Intranets (coming out soon)

This article will show you how to customize seach portlet, how to configure it and how to customize the look and feel of the portlet Search.

Search portlet

The Search Portlet (portlet ID 3) is a JSR-286 compliant portlet that can be used for federated search. By default, the portal itself is the search provider.

As shown in following figure, Search Portlet provides a federated search against Blogs entries, users, organizations,  Calendar entries, Bookmarks entries, Document Library documents, Image Gallery images, Message Boards message, Wiki articles, Web Content articles, Directory, etc. And moreover, Search Portlet provides a federated search against plugins portlets like Alfresco Content portlet, Knowledge Base portlet.

Note that when search assets, you would have ability to specify the scope of search results: Everything or This Community.  Everything means search results will come from any groups in current portal instance, like communities, organizations, and my community. This Community means search results will come from current group in the portal instance, like community Guest, organization “Palm Tree Enterprise” and My Community.

Above search results would cover Blogs entries, users, organizations,  Calendar entries, Bookmarks entries, Document Library documents, Image Gallery images, Message Boards message, Wiki articles, Web Content articles, Directory, etc. And moreover, search results will include assets from plugins portlets like Alfresco Content portlet. 

As you can see, search results would be displayed as a title with a link. If you have proper permission on an asset, you could click on the title with a link of the asset and view the asset as well. But if you don’t have proper permission on an asset, you could click on the title with a link of the asset and see permission error message.

What’s happening?
The portal provides many portlets to support OpenSearch framework, like Message Boards, Blogs, Wikis, Directory and Document Library, Users, Organizations, etc. In addition, plugins like Alfresco Content portlet also supports OpenSearch framework as shown in following screenshot. Normally, these portlets have following OpenSearch framework configuration.

<open-search-class>class-name</open-search-class>

The Search portlet obtains an OpenSearch instance from each portlet which has the tag <open-search-class> definition. For example, the portlet Directory (portlet ID 11) allows users to search for other users, organizations or user groups. OpenSearch has been specified for the portlet Directory in $PORTAL_ROOT_HOME/WEB-INF/liferay-portlet.xml as follows.

<open-search-class>com.liferay.portlet.directory.util.DirectoryOpenSearchImpl</open-search-class>

As shown in above code, the open-search-class value must be a class that implements com.liferay.portal.kernel.search.Open-Search, called to get search results in the OpenSearch standard.

Configuration

As mentioned above, OpenSearch in the search portlet cover out-of-out of Blogs, Calendar, Bookmarks, Document Library, Image Gallery, Message Boards, Wiki, Web Content, Directory, etc.  Fortunately, the portal adds ability to remove these portlets from the list of portlets searched by the portlet Search as follows.

com.liferay.portlet.blogs.util.BlogsOpenSearchImpl=true
com.liferay.portlet.bookmarks.util.BookmarksOpenSearchImpl=true
com.liferay.portlet.calendar.util.CalendarOpenSearchImpl=true
com.liferay.portlet.directory.util.DirectoryOpenSearchImpl=true
com.liferay.portlet.documentlibrary.util.DLOpenSearchImpl=true
com.liferay.portlet.imagegallery.util.IGOpenSearchImpl=true
com.liferay.portlet.journal.util.JournalOpenSearchImpl=true
com.liferay.portlet.messageboards.util.MBOpenSearchImpl=true
com.liferay.portlet.wiki.util.WikiOpenSearchImpl=true

As shown in above code, you can set any of above properties to false to disable the portlet from being searched by the search portlet in portal-ext.properties.

Above properties should be used for Liferay portal 6.0 or above (or 5.2 EE 5.2.7 SP3 or above).

For 5.2 or below, you can go to $PORTAL_ROOT_HOME/liferay-portlet.xml and comment out OpenSearch.

For more details, you could refer to the book: Liferay Portal 5.2 Systems Development

For example, if you don't want search results from Directory, you could do following.

<!-- <open-search-class>com.liferay.portlet.directory.util.DirectoryOpenSearchImpl</open-search-class>  -->

Similarly, you could apply the same on Blogs entries, users, organizations,  Calendar entries, Bookmarks entries, Document Library documents, Image Gallery images, Message Boards message, Wiki articles, Web Content articles, and custom portlets like Alfresco Content portlet, Knowledge Base portlet, etc.

Customization

In real cases, you may be required to use the portlet Search in different ways. Anyway, you would be able to customize the portlet Search. Here we’re going to discuss how to use the Search portlet in Social Office and how to use the Search portlet in themes.

The Social Office overrides the UI taglib <liferay-ui:search> in the portlet so-portlet through JSP files hooks in $AS_WEB_APP_HOME/so-portlet/META-INF/custom_jsps/html/taglib/ui/search/start.jsp as follows

<liferay-util:include page="/html/taglib/ui/search/start.portal.jsp" />
<c:if test="<%= group.isUser() %>">
 <script type="text/javascript">
  var searchOptions = jQuery('select[name=<%= namespace %>groupId] option');
  searchOptions.each(
   function(i) {
    var searchOption = jQuery(this);
    if (searchOption.val() != 0) {
     searchOption.remove();
    }
   }
  );
 </script>
</c:if>

As shown in above code, the social office overrides the look and feel of the portlet Search. For example, it will remove search options.

Of course, you can add the portlet Search in themes as runtime portlet. You could add Velocity template $theme.search() in the theme, specifically in the VM file portal_normal.vm or VM file included in portal_normal.vm.  For example, Social Office specified following lines in the theme so-theme, like $AS_WEB_APP_HOME/so-theme/templates/navigation_top.vm.

#if ($is_signed_in)
  <div class="my-search">$theme.search()</div>
#end

As shown in above code, when user signed in, the Social Office will show customized portlet Search in a style “my-search”.

For more information about OpenSearch in Liferay portal, you may refer to the book: Liferay Portal Enterprise Intranets.

Acknowledgements

I would like to thank team members at Liferay, especially thanks to Raymond Auge, Brian Chan, Bryan Cheung, Jorge Ferrer, Michael Young, Jerry Niu, Ed Shin, Craig Kaneko, Brian Kim, Bruno Farache, Thiago Moreira, Amos Fong, Scott Lee and David Truong of Liferay for providing the valuable information and all the support. Thanks to friends in Liferay community for providing comments and suggestions.

 

Blogues
Very Informative . Thanks for making me to know about open search in liferay portal. Sir, I have a doubt . Is this article related to Solr ?
Thanks. This article is for OpenSearch - the portlet Search. You could find more details related to Solr at http://www.liferay.com/community/wiki/-/wiki/Main/Integrate+Solr+with+Liferay+portal.
I am currently stuck in a scenario. I have many different datasets and i perform search on these datasets. I want to display the search results from each of the dataset in a seperate portlet. In order to do that i need as many portlets on the page as the number of datasets selected by the user. I need some way to instantiate multiple instances of a portlet (each instance will display different data). How is that possible? if at all? Or is there any other solution? I have been searching over the web and liferay forums for a way to do this but no success so far. Can you please help me here?
Hi Sulman, sorry to come back to you too late. Do you have your questions answered?
Hi Jonas,

I was wondering if one can modify the search portlet to filter data based on some meta-data like "date of creation/last modified", "author", "content type" etc? If yes, could you please give me a heads up on this particular feature..?

Thanks!
Hi Namrala, thanks. Yes, you can reach the same by JSP hooks.

Please let me know if you meet any issues,
Hey Jonas,

Thanks for you response. emoticon
But, I'm kind of a newbie.. Could you please elaborate on the steps or direct me to some detailed documentation?

I'm in urgent need of this one!!

Any help appreciated!

Thanks again...
I hava obtain this error

15:37:23,644 ERROR [jsp:1529] Error displaying content of type com.liferay.alfrescocontent.util.AlfrescoOpenSearchImpl: java.lang.NullPointerException
Hello,

Thanks for the post !

I've got the same error as elbuitro2002 :

I'm using search function with liferay (pluggued with alfresco), and I get :
Error displaying content of type com.liferay.alfrescocontent.util.AlfrescoOpenSearchImpl: java.lang.NullPointerException

After modifying ROOT\html\portlet\search\seach.jsp to add more logs, I get :
14:39:03,765 ERROR [jsp:1530] Error displaying content of type com.liferay.alfre
scocontent.util.AlfrescoOpenSearchImpl: java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.jsp.html.portlet.search.search_jsp._jspService(search_jsp.
java:1467)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

When I look in search_jsp.java, line 1467 is :
tagsString = tagsString.replaceAll("[\\[\\]]","");

NullPointerException is because tags is null.

And in fact, there's no tag XML element coming from Alfresco search.

I added then a if (tagsString!=null) in the JSP file and it just works fine now.

So this is a bug I think in liferay's search.jsp file.

My version :
- liferay 6.0.6
- Alfreco 3.4
Also, for Alfresco search :
In the search response, I only get a list a document of documents (link and filename) matching the search.
It would have been really cool to have the part of the document matching the search (à la Google).
I think it's because Alfresco OpenSearch API doesn't return this information (see http://wiki.alfresco.com/wiki/OpenSearch#Example_Responses).
How best can i configure so search results include assets of which are not viewable by guest users?
Hi Marc, Thanks. This can be done by the permission VIEW settings and checking.
Hi gonzalad, Thanks, that can be done in the Liferay portal by customizing federated indexing and search capabilities.
Hello all, any one knows how can I order the results of the search with a custom order (i. e. own algorithm).

Cheers.
Hi Andrés, yes it is possible. You could check the real example:

http://newsroom.cisco.com/
and the blogging post:

http://www.liferay.com/web/jonas.yuan/blog/-/blogs/building-social-media-rich-newsroom-on-top-of-liferay-portal

Hope that it helps,
Hi,
Is it possible to search content in portlet. Please advise.
Hi Jonas,
Can you please help me to provide some links how we can extend search functionality to Portal pages. I have some pages as portal pages in my website. I want to search content in my own portlet.

Thanks,
Bhagat
Hello Jonas,

I want LifeRay search to search a custom portlet as well that connects to other databases (federated search). I bought your book Liferay Portal 6 Enterprise Intranets but I couldn't find any related topic there. How should I go about it LifeRay 6, any guidance will be really appreciable.
As per you guys' instructions, I was able to successfully implement search indexing and open search on my custom portlet. It indexes my portlet data when running re-index process. But I have problem now, when I try to search, it gives me an exception stating "Error displaying content of type liferay open search... ", any help will be really appreciated.
have mention " com.liferay.portlet.messageboards.util.MBOpenSearchImpl=false" but still it is searching from message board.
Please tell me what more thing i need to modify.
Thanks in Advance
HI

We have EE 6.1 Liferay.
I want search should work like Any web search. The result displaycouple of rows from content.
Also I want to add variuos values to Search dropdown so that search should happen for selected section only.

Also I want to integrate search with data stored in Database.

How to do same?

Regards
Pankaj
Hi,
Can I extends or override the search for get what the user search and insert into BD? If yes how I can do it? Because it is not a service and I am not know how do it.
Thank you.
Hi Jonas.
Thank-you for the explanation. I'm using the $theme.search() in my navigation as you describe above.

How can I configure the used search portlet IN my Velocity template?
Especially I would like to know, how to configure the "View in Context" parameter. This should be set to "false".

Btw. I'm using LR 6.1 GA2.
Hi jonas,

How can I display third party sites content which are open search enabled in my portal search result .
Sir, I am currently trying to search on Share Point server and display the results in Liferay. Is it possible to do the same using this approach? It would be great if you can provide some inputs in this.
Hi Jonas Yuan,

What about Liferay DXP ? How to implement OpenSearch in DXP ? As I am unable to find any OpenSearch related properties in portal.properties to override. Can you please guide me ?