3 Replies Latest reply on Nov 7, 2014 9:54 AM by Horia Chiorean

    Query count to know total number of elements when paginating search results

    Guillem Folch Newbie

      How can we implement a query results count?


      We have 15.000 indexed nodes and we are trying to provide a search functionality with pagination.

      The idea is to use JCR limit and JCR offset parameters to just get the elements for the current page. However, we need also to provide the total number of elements of the search in order to being able to know how many pages are available.

      We have'nt seen this feature in JCR, so we we are doing a new query without limit and offset to get the number of elements of the resulting NodeIterator.

      This solution is working fine for a small number of query results, but if the search is returning all the documents (15.000 nodes) the search is taking too long (30s) and is consuming a lot of memory (600Mb) each time we ask for a page result.


      My question is, how we can just count the number of elements (like select count(*) from table)? Is there a way to implement it without having to instantiate all the nodes of the search?


      We are using Modeshape 3.8.0.


      Thanks in advance