Forums

Home » Liferay Portal » English » 3. Development

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

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.

 1
 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);
 5searchContext.setStart(QueryUtil.ALL_POS);
 6searchContext.setEnd(QueryUtil.ALL_POS);
 7searchContext.setAttribute("description", resultIndicator.getProductName());
 8searchContext.setKeywords(resultIndicator.getProductName());
 9Hits results = indexer.search(searchContext);
10               
11Document[] docs = results.getDocs();
12logger.info("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
Answer

Alberto Chaparro

LIFERAY STAFF

Rank: Regular Member

Posts: 134

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:
searchContext.setEnd(QueryUtil.ALL_POS);

is equivalent to
searchContext.setEnd(1);

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
Answer

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.