Cassandra (CQL) 中的结果分页 [英] Results pagination in Cassandra (CQL)

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

问题描述

我想知道如何使用 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.

在 MySQL 下使用 SQL,我可以做到以下几点:

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 中的 token 函数:https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useToken.html

Try using the token function in CQL: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useToken.html

另外一个建议,如果你使用的是 DSE,solr 支持深度分页:https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results

Another suggestion, if you are using DSE, solr supports deep paging: https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results

这篇关于Cassandra (CQL) 中的结果分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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