Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Ying Qi
Implementing search in a custom portlet
November 22, 2011 10:38 AM

Ying Qi

Rank: New Member

Posts: 11

Join Date: January 31, 2011

Recent Posts

I am working on a portlet where part of the application has to search through the Document Libraries that are deployed in the portal. However, when I run the search, it seems to only return 1 result for any search that I do. When I run the same exact search through one of the Document Library portlets, the results I expected are returned. So I was wondering if there was anything that I needed to modify in my SearchContext to change the number of results returned. Below is the code that I have written for the search.

 2Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class);
 3HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("com.liferay.portal.kernel.servlet.PortletServletRequest"));
 4SearchContext searchContext = SearchContextFactory.getInstance(request);
 7searchContext.setAttribute("description", resultIndicator.getProductName());
 9Hits results =;
11Document[] docs = results.getDocs();"Size of search results =  " + docs.length);

The size of the search results is always 1, the result is a valid result for the search, but there should be multiple items that satisfy the search.
Alberto Chaparro
RE: Implementing search in a custom portlet
April 25, 2012 9:44 AM

Alberto Chaparro


Rank: Expert

Posts: 284

Join Date: April 25, 2011

Recent Posts

Hi Shayan,

You can use the property searchContext.setEnd(LIMIT) to establish the limit of objects to return.

The following expression:

is equivalent to

The constant QueryUtil.ALL_POS only makes sense for Database Queries (At least in the version 6.1)

I hope this helps you.
Navin Singh
RE: Implementing search in a custom portlet
September 9, 2012 7:49 PM

Navin Singh

Rank: New Member

Posts: 8

Join Date: November 14, 2011

Recent Posts

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.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!