0

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

Alex Man
  • 4,746
  • 17
  • 93
  • 178
  • Please specify which Liferay version you are using and if you want to completely replace Liferay's search capabilities with your custom one or you want to have both (part of the site will one and another parts the other)? – Milen Dyankov Nov 28 '16 at 10:58
  • @MilenDyankov I am using `Liferay6.2GA6 Version` – Alex Man Nov 28 '16 at 11:28
  • @MilenDyankov I want to completely replace Liferay's search capabilities with my custom one – Alex Man Nov 28 '16 at 11:59

2 Answers2

3

Lifray uses search (actually index) for a lot of other things than just search portlet. If you only replace bits and pieces of it, something may stop working.

Good news is Liferay has pluggable search. In 6.2 by default it uses embedded Lucene but you can replace it with Solr. You can have a look at solr-web plugin for example to see how that is implemented. Particularly see how beans are wired with search configuration in solr-spring.xml

That said, I guess you have few options to achive what you want:

  • fully implement a new search plugin based on your custom service that can index and search every entity that Liferay expects to be indexed.
  • implement a new search plugin that will somehow distinguish between "your" search and "internal" search/index and send requests to different places
  • implement your own portlet that does what you want independant of Liferay's search
Milen Dyankov
  • 2,972
  • 14
  • 25
1

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())
Ahmedbc
  • 76
  • 3
  • Thanks for the reply..........Lets say I create a custom portlet which contains a serach box and its implementation, but how we can replace with the theme search box, do we need to write a hook to get it replaced with our custom portlet in theme – Alex Man Nov 29 '16 at 04:17