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

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

问题描述

我正在搜索用户搜索各种关键字时记录数据。我想生成的是一份报告,其中列出了用户已搜索的所有唯一关键字,并按升序和降序排列,每次搜索的次数。


$ b $



谢谢!

div class =h2_lin>解决方案

根据 eBay技术博客,常见的是将计数器值存储在密钥本身中。所以为了存储次数,Bob,Ken和Jimmy登录了一个网站,单行如下:




logins:[(0001_Bob,''),(0002_Bob,''),...,(0010_Ken,''),(0012_Jimmy,''),...]



请注意,您的键会自动排序,尾端最高计数,这接近于一个常数时间查找。



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




login_count:[(Bob,2),(Ken,10),(Jimmy,10),...]


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.

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

Thanks!

解决方案

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:

logins: [(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天全站免登陆