Cassandra 按计数排序结果 [英] Cassandra sorting results by count

查看:27
本文介绍了Cassandra 按计数排序结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在记录有关搜索各种关键字的用户的数据.我想生成一份报告,其中包含用户搜索过的所有唯一关键字,并按每个关键字的搜索次数按升序和降序排序.

I am recording data on users searching for various keywords. What I'd like to produce is a report of all of the unique keywords that the users have searched for, sorted in ascending and descending order by how many times each has been searched for.

这是否可以使用 Cassandra 建模,如果可以,模型会是什么样子?

Is this something that can be modeled using Cassandra, and if so what would the model look like?

谢谢!

推荐答案

根据eBay 技术博客,将计数器值存储在键本身中并不罕见.因此,要存储 Bob、Ken 和 Jimmy 登录网站的次数,一行将如下所示:

According to the eBay tech blog, it's not unusual to store your counter values in the key itself. So to store the number of times, Bob, Ken, and Jimmy logged into a website, a single row would look as follows:

<代码>登录: [(0001_Bob,''), (0002_Bob, ''), ..., (0010_Ken, ''), (0012_Jimmy, ''), ...]

请注意,您的密钥将自动以尾部最高计数自行排序,这接近于恒定时间查找.

Notice that your keys will automatically sort themselves with the highest count at the tail-end and this is close to a constant time look-up.

请注意,每次您的用户登录时,都会创建一个新的列键.您必须在另一行中跟踪登录次数,以便快速查找到目前为止发生的登录次数以及下一个键应具有的整数值:

Note that everytime your user logs-in, a new column key is created. You'd have to keep track of the number of log-ins in another row so that you have a fast look-up for how many log-ins have occurred so far and what integer value your next key should have:

<代码>login_count: [(Bob, 2), (Ken, 10), (Jimmy, 10), ...]

这篇关于Cassandra 按计数排序结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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