Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Pagination issue using Searchresult api - getResultPage

Avatar

Level 3

Hi All,

I badly need someone to help me. we were implementing pagination in CQ5. We want something similar to google pagination - For example, I want to show 10 results per page and after page 6, I want to move the pagination numbers one by one. ie. first it will show 1 2 3 4.......10 and after page 6 is clicked, it need to show 2 3 4 5 6 7 8 9 10 11 and then for page 11 is clicked then 5 6 7 8 9 10 11 12 13 14 etc. And in the last page we just show last page - 10 pages. 

We tried implementing this but this was too complexed as we tried to do as showed below.

private List<ResultPage> extractSubList(SearchResult result){
        long currentIndex = result.getStartIndex() / result.getHitsPerPage();
        int startIndex = (int)currentIndex - 5;
        int endIndex = (int)startIndex + 10;
        startIndex = startIndex < 0 ? 0 : startIndex;
        endIndex = endIndex >= result.getResultPages().size() ? result.getResultPages().size() : endIndex;
        List<ResultPage> subList = result.getResultPages().subList(startIndex, endIndex);
        return subList;
    }

Though this logic works fine for us till 11th page but as soon as we move to 12th page, the resultPage list index changes and also the result page size changes and hence we could not provide proper start and end indexes. Also we tried to restrict 10 numbers to display but could do that.

Can someone please help me in acheiving this functionality? Let me know where we are doing wrong.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Are you trying to develop an AEM Search component - like the one shown in the geometrixx sample site:

http://localhost:4502/cf#/content/geometrixx/en/toolbar/search.html?q=Circles&cq_ck=1423678319366

If you are having issues implementing a custom search component - take a look at the logic in the out of the box component: 

/libs/foundation/components/search

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

Are you trying to develop an AEM Search component - like the one shown in the geometrixx sample site:

http://localhost:4502/cf#/content/geometrixx/en/toolbar/search.html?q=Circles&cq_ck=1423678319366

If you are having issues implementing a custom search component - take a look at the logic in the out of the box component: 

/libs/foundation/components/search