searchliferayliferay-6.2

Liferay Search Portlet Customization


I have a requirement in which I need to override the Liferay Default Search functionality in such a way that, whenever a user searches it should work in the following way:

Already some third party restful services is available which return the result for any search keywords, Let say the search key work is "Test", if we pass "Test" to the third party services it will return the result in the form of json, which we need to display within the search result page.

I plan to achieve this by the following way, but would like to know form you guys whether I am doing the right way.

Step 1: I will create a hook project where I will override the main_search_result_form.jsp to format the result page.

Step 2: I will create a Indexer where I will implement and make a call to the restful service with the search keyword, I will return the resultant json object.

Step 3: I will get the json in main_search_result_form.jsp and I will format the page based on that json output

Like to know whether My approach is correct


Solution

  • My advice is to create a new portlet and don't hook the existing search portlet for the following reasons :

    -The power of the Liferay search portlet is the use of the Apache Lucene search engine to search and index the portal contents, entities... and since you don't want search results from the portal it will useless to hook it.

    -The search portlet jsp's are coded with a certain render logic that probably will be different from your logic ( specially with json results ) so i think you will have to make big modifications on those jsp's and it will be an overhead.

    -Your need is relatively simple (Invoking a web service with a search term parameter getting the results and rendering them).

    So i think a simple Liferay MVC portlet will be a better choice for you.

    Replacing the theme default search with your custom search portlet

    No you don't need a hook. You can replace the theme search field by editing your portal_normal file as following:

    Replace

    $theme.journalContentSearch()
    

    By

    ## Set the portlet preferences if you need  ##
    #set ($VOID = $velocityPortletPreferences.setValue('display-style', '1'))
    #set ($VOID = $velocityPortletPreferences.setValue('portlet-setup-show-borders', 'false'))
    
    #set ($instanceId = 'A2R4')
    #set ($portletId = 'YOUR_CUSTOM_SEARCH_PORTLET_ID')
    #set ($myPortlet = "${portletId}_INSTANCE_${instanceId}")
    
    $theme.runtime($myPortlet, '', $velocityPortletPreferences.toString())
    
    #set ($VOID = $velocityPortletPreferences.reset())