0

I have a question about the good way to use pagination with Alfresco. I know the documentation (https://wiki.alfresco.com/wiki/4.0_JavaScript_API#Search_API) and I use with success the query part. I mean by that that I use the parameters maxItems and skipCount and they work the way I want. This is an example of a query that I am doing :

 var paging =
  {
     maxItems: 100,
     skipCount: 0
  };
  var def =
  {
     query: "cm:name:test*"
     page: paging
  };
  var results = search.query(def);

The problem is that, if I get the number of results I want (100 for example), I don't know how to get the maxResults of my query (I mean the total amount of result that Alfresco can give me with this query). And I need this to :

  1. know if there are more results
  2. know how many pages of results are lasting

I'm using a workaround for the first need : I'm doing a query for (maxItems+1), and showing only maxItems. If I have maxItems+1, I know that there are more results. But this doesn't give me the total amount of result.

Do you have any idea ?

edi9999
  • 19,701
  • 13
  • 88
  • 127
Akah
  • 1,890
  • 20
  • 28

2 Answers2

1

With the javascript search object you can't know if there are more items. This javascript object is backed by the class org.alfresco.repo.jscript.Search.java. As you can see the query method only returns the query results without any extra information. Compare it with org.alfresco.repo.links.LinkServiceImpl which gives you results wrapped in PagingResults.

So, as javacript search object doesn't provide hasMoreItems info, you need to perform some workaround, for instance first query without limits to know the total, and then apply pagination as desired.

togomez
  • 664
  • 6
  • 6
0

You can find how many objects have been found by your query simply calling

results.length

paying attention to the fact that usually queries have a configured maximum result set of 1000 entries to save resources. You can change this value by editing the <alfresco>/tomcat/webapps/alfresco/WEB_INF/classes/alfresco/repository.properties file.

So, but is an alternative to your solution, you can launch a query with no constraints and obtain the real value or the max results configured. Then you can use this value to devise how many pages are available basing you calculation on the number of results for page. Then dinamically pass the number of the current page to the builder of your query def and the results variable will contain the corresponding chunk of data.

In this SO post you can find more information about pagination.

Community
  • 1
  • 1
abarisone
  • 3,707
  • 11
  • 35
  • 54
  • 1
    After verification, results.length doesn't give me the total number of elements, but the number of elements in my "page" (so maxItems at most). I may have badly understood your answer. – Akah Sep 15 '15 at 10:07