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 ?

4

2 回答 2

1

使用 javascript 搜索对象,您无法知道是否还有更多项目。这个 javascript 对象由org.alfresco.repo.jscript.Search.java类支持。如您所见,查询方法仅返回查询结果,没有任何额外信息。将其与 org.alfresco.repo.links.LinkServiceImpl进行比较,后者会为您提供包含在 PagingResults 中的结果。

因此,由于 javacript 搜索对象不提供hasMoreItems信息,您需要执行一些解决方法,例如首先无限制地查询以了解总数,然后根据需要应用分页。

于 2015-09-16T07:07:42.057 回答
0

您只需调用即可找到查询找到了多少对象

results.length

请注意,通常查询配置的最大结果集为 1000 个条目以节省资源。您可以通过编辑<alfresco>/tomcat/webapps/alfresco/WEB_INF/classes/alfresco/repository.properties文件来更改此值。

因此,但作为您的解决方案的替代方案,您可以启动没有约束的查询并获得实际值或配置的最大结果。然后,您可以使用此值根据您计算的页面结果数来设计可用的页面数。然后动态地将当前页面的编号传递给查询定义的构建器,结果变量将包含相应的数据块。

在这篇SO 帖子中,您可以找到有关分页的更多信息。

于 2015-09-15T09:24:14.263 回答