How to use Liferay search service inside my own module?

678 Views Asked by At

I have a requirement with Liferay 7.1. I need to create a search page where the user can see the result organized into columns by some categories. I've been thinking two approaches:

  1. Create some logic in the theme to completely change the search page and organize the data
  2. Create a module that uses the same search service that Liferay actually uses.

I rather chose the second approach because I don't want to mess with the DOM and I think it's easier to make my own page, but I haven't been able to find that service, could anyone give me some information about that search service I need to use?

I tried to use this one as a guide: https://github.com/liferay/com-liferay-portal-search/blob/master/portal-search-web/src/main/java/com/liferay/portal/search/web/internal/portlet/SearchPortlet.java; but I couldn't create a PortalOpenSearchImpl instance.

1

There are 1 best solutions below

0
On

First of all, see the options mentioned in this answer. Perhaps you can simply assemble the page from existing widgets and just customize the look and feel.

If that is not an option then you need to create custom portlet. From your question I understand you are going down that road, but you are looking at the wrong code. The link you pasted is from the time Liferay used separate repos for modules. However it's now back to monorepo. Here is the code of the Search Portlet of version 7.1

It is not possible to explain here how the whole search infrastructure in the portal works. Have a look at the content of the portal-search folder to get an idea of the complexity of that functionality. All I can do is give you some links to the relevant sections of the documentation:

as well as links to same (perhaps relevant) samples: