2013-05-02 40 views
2

我從IMDB(電影列表)從這裏下載電影:http://www.imdb.com/interfaces這個Redis排序集中的頂級電影是什麼?

我想算一個給定的電影是如何經常出現在列表中有幫助的Redis排序集合,但我有點疑惑的結果:

 
redis 127.0.0.1:6379> zrangebyscore 'movies:title' 5000 +inf WITHSCORES 
1) "Countdown" 
2) "5254" 
3) "The Bold and the Beautiful" 
4) "5322" 
5) "Days of Our Lives" 
6) "5451" 
7) "Neighbours" 
8) "6442" 
9) "The New Price Is Right" 
10) "7633" 
11) "Coronation Street" 
12) "8097" 

我想要最常出現在最上面的電影。另外,我對比分感到困惑。這5k,6k,7k是什麼意思?

我用我的實驗的腳本是一個Rake任務是這樣的:

 
    task :import do 
    file = File.new(ENV['file']) 
    redis = Redis.new 
    file.each_line do |l| 
     if l =~ /^"(.*)"/ 
     puts $1 
     redis.zincrby 'movies:title', 1, $1 
     end 
    end 
+0

嗯。 Redis當然是正確的:cat db/movies_utf.txt | grep「我們的日子」| wc - > 5462 - >問題出在數據集中。 – poseid 2013-05-03 06:25:28

回答

1

您可能需要使用zrevrangebyscore代替zrangebyscore的嘗試。

語法:

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] 

例如,你的情況:

zrangebyscore 'movies:title' +inf 5000 WITHSCORES 

Reference