Cassandra sorting results by count

前端 未结 2 1265
半阙折子戏
半阙折子戏 2021-01-19 05:27

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

2条回答
  •  广开言路
    2021-01-19 06:01

    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), ...]

提交回复
热议问题