List<Search.Page> resultPages = result.getResultPages()
Hi - I want to understand how the result.getResultPages(); work from wcm Search. Also how does resultPage.getURL() and resultPage.getIndex() works. All pointers and help appreciated
~Nitin
Hi - I want to understand how the result.getResultPages(); work from wcm Search. Also how does resultPage.getURL() and resultPage.getIndex() works. All pointers and help appreciated
~Nitin
Hi there,
the javadoc for this topic is actually quite good (http://wem.help.adobe.com/enterprise/en_US/10-0/wem/javadoc/com/day/cq/search/result/SearchResult.html).
Even better is to take a look at the standard search component, but I can try to digest it a bit from my experience.
getResultPages
When you have done a search with help of the components and classes inside AEM, you have access to the "result object" from the interface SearchResult.
This object has the great function getResultPages() which will return a normal java.util list (of ResultPages).
These pages can be explained as a collection of hits. Basically you set the number of hits you want per page and the search calculates how many pages that would result in.
It then arranges the hits on the required amount of pages. These pages can then later on be used for pagination the the search results and works just like any search function on e.g. Google. There you see that the results are presented, a few at a time, on different result pages and you can click on any page number to see more results.
resultPage.getURL()
Lets say the the search returned 30 hits and we wanted to display 10 results per page. Then we would automatically get 3 resultpages. For the search component to know which page we want to view we must supply the page it is located on with some kind of number. This is sometimes done by the following syntax
"seach.html?q=searchtext&page=2" telling the component that we want to display the second page in this case.
When using the the resultPage, you will autmatically get the required url for the component by using resultPage.getURL(). This can then be used as a <a href ..> link to display the next set of hits. For example if we look at the standard search component is is quite neatly used like this:
To display the previus result page we first check if there is a previous page and the get that page from the result with the getPreviousPage(). Then we use the getURL() function on that page and use it as the link.
<c:if test="${result.previousPage != null}"> <a href="${result.previousPage.URL}"><fmt:message key="previousText"/></a> </c:if>This goes for the next result page aswell which works in just the same way.
<c:if test="${result.nextPage != null}"> <a href="${result.nextPage.URL}"><fmt:message key="nextText"/></a> </c:if>
resultPage.getIndex()
This function simply returns the index or positon in the list which the result page is is. If its the third page, the getIndex() function will return 2, since that's the behvious of Lists in java. This is used in the standard component as follows:
<c:when test="${page.currentPage}">${page.index + 1}</c:when>Here it checks if the resultpage is the current page and then displays the current page index + 1 to get the actual number as we would count it and not the index.
I hope this will help you in some way
/Johan
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.