4 Replies Latest reply on Nov 16, 2012 2:11 AM by shin4649

    Iterator Pagination

    shin4649

      Hi,

       

      I've used Query Builder to retrieve a Iterator<Node> to display images. I know there is list pagination. But how do I divide the iterator to different pages?

        • 1. Re: Iterator Pagination
          crestenst Level 1

          Someone should correct me if i'm wrong, but...

           

          I believe the way this is done is using the setHitsPerPage(long) and the setStart(long) methods of the Query object.

           

          Hits per page will be the number of hits in the list, while the start will be the position of the overall results you start the list at.

           

          So if you only wanted one result in your list, and you wanted the second hit in the list, you would do something like this:

           

          (object).setHitsPerPage(1);

          (object).setStart(1);

           

          (http://dev.day.com/docs/en/cq/5-3/javadoc/com/day/cq/search/Query.html)

          • 2. Re: Iterator Pagination
            shin4649 Level 1

            So I have done this:

             

                builder = resource.getResourceResolver().adaptTo(QueryBuilder.class);

                query = builder.createQuery(PredicateGroup.create(map), currentNode.getSession());

                query.setHitsPerPage(2);

                result = query.getResult();

                Iterator<Node> imageIterator = result.getNodes();

             

            It printed the results of the first resultPage. How do I get the next resultPage if there is no getURL?

            • 3. Re: Iterator Pagination
              crestenst Level 1

              builder = resource.getResourceResolver().adaptTo(QueryBuilder.class);

                  query = builder.createQuery(PredicateGroup.create(map), currentNode.getSession());

                  query.setHitsPerPage(2);

                 query.setStart(2)

                  result = query.getResult();

                  Iterator<Node> imageIterator = result.getNodes();

               


              is how you would get the next page.

               

              What I recommend doing is this: import all of the search results onto your web-page, and do pagination through js. I use the DataTables js plugin to accomplish this.

               

              http://datatables.net/

              • 4. Re: Iterator Pagination
                shin4649 Level 1

                crestenst wrote:

                 

                builder = resource.getResourceResolver().adaptTo(QueryBuilder.class);

                    query = builder.createQuery(PredicateGroup.create(map), currentNode.getSession());

                    query.setHitsPerPage(2);

                   query.setStart(2)

                    result = query.getResult();

                    Iterator<Node> imageIterator = result.getNodes();

                 


                is how you would get the next page.

                 

                What I recommend doing is this: import all of the search results onto your web-page, and do pagination through js. I use the DataTables js plugin to accomplish this.

                 

                http://datatables.net/

                 

                 

                Thanks!

                 

                Just have to remember to set query HitsPerPage to "0".