Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay Search Portlet
Hello,
I am new to Liferay and have a requirement to develop a Search Portlet in Liferay 7.1, which does simple search from Liferay database based on the selected dropdown options as inputs and displys the result. Anybody could you help me with this in developing such portlet.
Thanks in Advance.
Regards,
Pavan
I am new to Liferay and have a requirement to develop a Search Portlet in Liferay 7.1, which does simple search from Liferay database based on the selected dropdown options as inputs and displys the result. Anybody could you help me with this in developing such portlet.
Thanks in Advance.
Regards,
Pavan
Hi Pavan,
Welcome to the community
For the record, there are actually two different search portlets that come out of the box with Liferay and they're pretty configurable, so I would consider checking those out before rolling your own search portlet. Check this resource out: https://dev.liferay.com/en/discover/portal/-/knowledge_base/7-1/whats-new-with-search
If you HAVE to build your own portlet, ...
For your search, are you searching across multiple entity types? (web content, documents, users, etc) or is your requirement just to provide search functionality for a single type of asset?
Welcome to the community

I am new to Liferay and have a requirement to develop to Search Portlet in Liferay 7.1
For the record, there are actually two different search portlets that come out of the box with Liferay and they're pretty configurable, so I would consider checking those out before rolling your own search portlet. Check this resource out: https://dev.liferay.com/en/discover/portal/-/knowledge_base/7-1/whats-new-with-search
If you HAVE to build your own portlet, ...
does simple search from Liferay database based on the selected dropdown options as inputs and displys the resultI wouldn't recommend building a search portlet that uses database queries. Liferay 7.1 uses Elasticsearch out of the box and has an rich (wrapper) Search API that can be used to to run queries against the search index rather than the database. Your application is already pushing enough load at the database for things that can't be sourced from search, so anything you can offload onto search you probably should.
For your search, are you searching across multiple entity types? (web content, documents, users, etc) or is your requirement just to provide search functionality for a single type of asset?
Hi Andrew,
Thanks for your response.
I can explain in detail my requirement. Currently we have around 10K+ rows of data in excel and end users does search the required content by applying filter.
But now we are planning to transfer this complete data into Liferay DB and put a search portlet to do this job for end user. So basically we dont have to search for any asset but i hope just one table in Liferay does this job and is it possible to achieve this by running queries against the search index rather than the database.
So could you provide your suggestions. Thank you in adavance.
Regards,
Pavan
Thanks for your response.

I can explain in detail my requirement. Currently we have around 10K+ rows of data in excel and end users does search the required content by applying filter.
But now we are planning to transfer this complete data into Liferay DB and put a search portlet to do this job for end user. So basically we dont have to search for any asset but i hope just one table in Liferay does this job and is it possible to achieve this by running queries against the search index rather than the database.
So could you provide your suggestions. Thank you in adavance.
Regards,
Pavan
First, you create the table(s) and fields with Service Builder. There you will store the data.
https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-0/what-is-service-builder
It creates the usual create/read/update/delete methods for you.
From there, you have two options:
a) Search in the database
b) Add the data to the search index
Method a) is usually less work, especially if you are new to Liferay. Also, if you need to simply filter on a few fields, service builder can generate finder methods too. I think, this is also the better approach in your case, since you probably have just one table with a few lines.
Method b) can be better if you have different kinds of data. e.g. Webcontent, images, forum entries, products. ... and you want to query all of them.
https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-0/what-is-service-builder
It creates the usual create/read/update/delete methods for you.
From there, you have two options:
a) Search in the database
b) Add the data to the search index
Method a) is usually less work, especially if you are new to Liferay. Also, if you need to simply filter on a few fields, service builder can generate finder methods too. I think, this is also the better approach in your case, since you probably have just one table with a few lines.
Method b) can be better if you have different kinds of data. e.g. Webcontent, images, forum entries, products. ... and you want to query all of them.
Hi Pavan,
Christoph beat me to it I guess
. His advice is sound -- it sounds like service builder is all you need. There are definitely multiple ways to solve this one, but as he said, being new to Liferay, it's probably your simplest (and best documented) approach.
When you manage to get that going though, if you are interested in learning how to do it with search, come back and we can walk you through the next steps.
Christoph beat me to it I guess

When you manage to get that going though, if you are interested in learning how to do it with search, come back and we can walk you through the next steps.
Hi Christoph / Andrew,
Thank you for the suggestions.
I was able to create the table structure using the Liferay service builder. Also able to display the table using Searchcontainer along with standard CRUD entry options inside the portlet.
Now coming to the search filter, i did some research but couldn't understand completely on the Liferay searchContext and indexing . Do you have any sample code snippet which can help me in implementing this ?
Thanks in advance.
Pavan
Thank you for the suggestions.
I was able to create the table structure using the Liferay service builder. Also able to display the table using Searchcontainer along with standard CRUD entry options inside the portlet.
Now coming to the search filter, i did some research but couldn't understand completely on the Liferay searchContext and indexing . Do you have any sample code snippet which can help me in implementing this ?
Thanks in advance.
Pavan
Are you sure that you need to use search? If I recall correctly, searchcontainer has "nothing" to do with search and the data can also come from the database.
If you want to go with search, then:
In 7.0 you had to create an indexer
https://portal.liferay.dev/docs/7-0/tutorials/-/knowledge_base/t/creating-an-entry-indexer
This has changed somewhat in 7.1, but I am not sure how much has changed. I didn't need it so far. But the 7.0 way should work too.
https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/indexing-framework
When you have done that, regular search should be able to find your items. Then you can go on and implement your own search.
If you want to go with search, then:
In 7.0 you had to create an indexer
https://portal.liferay.dev/docs/7-0/tutorials/-/knowledge_base/t/creating-an-entry-indexer
This has changed somewhat in 7.1, but I am not sure how much has changed. I didn't need it so far. But the 7.0 way should work too.
https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/indexing-framework
When you have done that, regular search should be able to find your items. Then you can go on and implement your own search.
Great progress Pavan,You need to have your search filter and order parameters defined in a -DisplayTerms and -SearchTerms file, and then reference them in a -Search file, which you then reference from your searchcontainer.
Example [com.liferay.portlet.usersadmin.search.UserSearchTerms]
Also, which interface are you using for your search display on jsp. If you are using clay:navigation styles (instead of liferay-ui), then you need to display some additional search-related items in a display context file.
Eg.[com.liferay.users.admin.web.internal.display.context.ViewUsersManagementToolbarDisplayContext]
I suggest you take a good look at these comprehensive examples in liferay source code. Should get you moving. Please let us know if you're stuck anywhere.
David
Example [com.liferay.portlet.usersadmin.search.UserSearchTerms]
public class UserSearchTerms extends UserDisplayTerms {
public UserSearchTerms(PortletRequest portletRequest) {
super(portletRequest);
emailAddress = DAOParamUtil.getString(portletRequest, EMAIL_ADDRESS);
firstName = DAOParamUtil.getString(portletRequest, FIRST_NAME);
lastName = DAOParamUtil.getString(portletRequest, LAST_NAME);
middleName = DAOParamUtil.getString(portletRequest, MIDDLE_NAME);
organizationId = ParamUtil.getLong(portletRequest, ORGANIZATION_ID);
roleId = ParamUtil.getLong(portletRequest, ROLE_ID);
screenName = DAOParamUtil.getString(portletRequest, SCREEN_NAME);
status = ParamUtil.getInteger(
portletRequest, STATUS, WorkflowConstants.STATUS_APPROVED);
userGroupId = ParamUtil.getLong(portletRequest, USER_GROUP_ID);
}
}
This defines LAST_NAME, FIRST_NAME, etc as search terms or filters. You simply replace them with your own filters.Also, which interface are you using for your search display on jsp. If you are using clay:navigation styles (instead of liferay-ui), then you need to display some additional search-related items in a display context file.
Eg.[com.liferay.users.admin.web.internal.display.context.ViewUsersManagementToolbarDisplayContext]
public PortletURL getPortletURL() {
try {
PortletURL portletURL = PortletURLUtil.clone(
_currentURL, _renderResponse);
portletURL.setParameter("orderByCol", getOrderByCol());
portletURL.setParameter("orderByType", getOrderByType());
return portletURL;
}
catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn(e, e);
}
return _renderResponse.createRenderURL();
}
}
public String getSearchActionURL() {
PortletURL searchActionURL = getPortletURL();
return searchActionURL.toString();
}
I suggest you take a good look at these comprehensive examples in liferay source code. Should get you moving. Please let us know if you're stuck anywhere.
David
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™