问题描述
我想知道如何使用Cassandra实现分页。
I am wondering how can I achieve pagination using Cassandra.
让我们说我有一个博客。博客列出每页最多10个帖子。要访问下一个帖子,用户必须点击分页菜单才能访问第2页(帖子11-20),第3页(第21-30页)等。
Let us say that I have a blog. The blog lists max 10 posts per page. To access next posts a user must click on pagination menu to access page 2 (posts 11-20), page 3 (posts 21-30), etc.
使用SQL在MySQL下,我可以做以下:
Using SQL under MySQL, I could do the following:
SELECT * FROM posts LIMIT 20,10;
LIMIT的第一个参数偏离结果集的开头,第二个参数是行的数量取。上述示例返回从第20行开始的10行。
The first parameter of LIMIT is offset from the beginning of result set and second argument is amount of rows to fetch. The example above returns 10 rows starting from row 20.
如何在CQL中实现相同的效果?
How can I achieve the same effect in CQL?
我在Google上找到了一些解决方案,但所有这些解决方案都需要有上次查询的最后一个结果。它适用于有下一个按钮分页到另一个10结果集,但如果我想从第1页跳到第5页怎么办?
I have found some solutions on Google, but all of them require to have "the last result from previous query". It works for having "next" button to paginate to another 10-results-set, but what if I want to jump from page 1 to page 5?
推荐答案
尝试使用CQL中的令牌函数:
Try using the token function in CQL:http://www.datastax.com/documentation/cql/3.0/cql/cql_using/paging_c.html
另一个建议是,如果您使用DSE, solr支持深度分页:
Another suggestion, if you are using DSE, solr supports deep paging:https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results
这篇关于结果分页Cassandra(CQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!