Apache CMIS:分页查询结果 [英] Apache CMIS: Paging query result

查看:104
本文介绍了Apache CMIS:分页查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始使用Apache CMIS,并阅读了官方文档和示例.我还没有注意到有关分页查询结果的任何信息.

Recently I've started using Apache CMIS and read the official documentation and examples. I haven't noticed anything about paging query results.

有一个示例显示了如何列出文件夹项目,并使用operationContext设置maxItemsPerPage,但是似乎可以在getChilder方法中使用operationContext:

There is an example showing how to list folder items, setting maxItemsPerPage using operationContext, but it seems that operationContext can be used inside getChilder method:

int maxItemsPerPage = 5;
int skipCount = 10;
CmisObject object = session.getObject(session.createObjectId(folderId));
Folder folder = (Folder) object;
OperationContext operationContext = session.createOperationContext();
operationContext.setMaxItemsPerPage(maxItemsPerPage);
ItemIterable<CmisObject> children = folder.getChildren(operationContext);
ItemIterable<CmisObject> page = children.skipTo(skipCount).getPage();

在列出u文件夹时可以.但是我的案例是关于从自定义搜索查询中获取结果.基本方法是:

This is ok when it comes to listing u folder. But my case is about getting results from custom search query. The basic approach is:

String myType = "my:documentType";
ObjectType type = session.getTypeDefinition(myType);
PropertyDefinition<?> objectIdPropDef = type.getPropertyDefinitions().get(PropertyIds.OBJECT_ID);
String objectIdQueryName = objectIdPropDef.getQueryName();
String queryString = "SELECT " + objectIdQueryName + " FROM " + type.getQueryName();
ItemIterable<QueryResult> results = session.query(queryString, false);
for (QueryResult qResult : results) {
    String objectId = qResult.getPropertyValueByQueryName(objectIdQueryName);
    Document doc = (Document) session.getObject(session.createObjectId(objectId));
}

这种方法将检索queryResult中的所有文档,但是我想包括startIndex和limit.想法是键入这样的内容:

This approach will retrieve all documents in a queryResult, but I would like to include startIndex and limit. The idea would be to type something like this:

ItemIterable<QueryResult> results = session.query(queryString, false).skipTo(startIndex).getPage(limit);

我不确定这部分:getPage(limit).这是分页的正确方法吗?另外,我想检索项目总数",所以我知道如何在显示我的项目的网格中设置最大项目数.有一种方法,但是在文档中写了一些奇怪的东西,例如有时存储库无法识别最大项目数.这就是这种方法:

I'm not sure about this part: getPage(limit). Is this right approach for paging? Also I would like to retrieve Total Number of Items, so I could know how to set up the max items in grid where my items will be shown. There is a method, but something strange is written in docs, like sometimes the repository can't be aware of max items. This is that method:

results.getTotalNumItems();

我尝试过类似的事情:

SELECT COUNT(*)...

但这并不能解决问题:)

but that didn't do the trick :)

请,您能给我一些建议如何根据查询结果进行正确的分页吗?

Please, could you give me some advice how to do a proper paging from a query result?

谢谢.

推荐答案

查询返回与getChildren返回相同的ItemIterable,因此您可以分页查询返回的结果集,就像分页getChildren返回的结果集一样.

Query returns the same ItemIterable that getChildren returns, so you can page a result set returned by a query just like you can page a result set returned by getChildren.

假设您有一个结果页面,该页面上显示20个项目.考虑一下我正在OpenCMIS Workbench的Groovy控制台中针对包含149个名为testN.txt的文件的文件夹运行的代码段:

Suppose you have a result page that shows 20 items on the page. Consider this snippet which I am running in the Groovy Console in the OpenCMIS Workbench against a folder with 149 files named testN.txt:

int PAGE_NUM = 1
int PAGE_SIZE = 20
String queryString = "SELECT cmis:name FROM cmis:document where cmis:name like 'test%.txt'"

ItemIterable<QueryResult> results = session.query(queryString, false, operationContext).skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE)

println "Total items:" + results.getTotalNumItems()

for (QueryResult result : results) {
   println result.getPropertyValueByQueryName("cmis:name")
}

println results.getHasMoreItems()

当您以PAGE_NUM = 1运行它时,您将获得20个结果,并且最后一个println语句将返回true.还要注意,第一个println将打印149,即与搜索查询匹配的文档总数,但是正如您指出的那样,并非所有服务器都知道如何返回该值.

When you run it with PAGE_NUM = 1, you'll get 20 results and the last println statement will return true. Also note that the first println will print 149, the total number of documents that match the search query, but as you point out, not all servers know how to return that.

如果使用PAGE_NUM = 7重新运行此代码,则将获得9个结果,并且由于位于列表的末尾,最后一个println返回false.

If you re-run this with PAGE_NUM = 7, you'll get 9 results and the last println returns false because you are at the end of the list.

如果要查看一个利用OpenCMIS和普通servlet和JSP页面的工作搜索页面,请查看The Blend ,这是随书CMIS& Apache Chemistry in Action.

If you want to see a working search page that leverages OpenCMIS and plain servlets and JSP pages, take a look at the SearchServlet class in The Blend, a sample web app that comes with the book CMIS & Apache Chemistry in Action.

这篇关于Apache CMIS:分页查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆