Module: ActsAsMongoRateable::ClassMethods
- Defined in:
- lib/acts_as_mongo_rateable/acts_as_mongo_rateable.rb
Instance Method Summary collapse
-
#highest_bayesian_rated(limit = 1) ⇒ Object
TO DO this is awful, awful, awful! make it faster using map/reduce.
- #highest_rated(limit = 1) ⇒ Object
- #most_rated(limit = 1) ⇒ Object
- #most_rated_by_authorities(limit = 1) ⇒ Object
Instance Method Details
#highest_bayesian_rated(limit = 1) ⇒ Object
TO DO this is awful, awful, awful! make it faster using map/reduce
17 18 19 20 21 22 23 24 |
# File 'lib/acts_as_mongo_rateable/acts_as_mongo_rateable.rb', line 17 def highest_bayesian_rated(limit=1) stats = all({:select => 'id, rating_stats'}) all.sort_by do |doc| = doc.(stats) doc.['bayesian_rating'] = end.reverse[0,limit] end |
#highest_rated(limit = 1) ⇒ Object
4 5 6 |
# File 'lib/acts_as_mongo_rateable/acts_as_mongo_rateable.rb', line 4 def highest_rated(limit=1) all({:order => "rating_stats.average DESC", :limit => limit}) end |
#most_rated(limit = 1) ⇒ Object
8 9 10 |
# File 'lib/acts_as_mongo_rateable/acts_as_mongo_rateable.rb', line 8 def most_rated(limit=1) all({:order => "rating_stats.count DESC", :limit => limit}) end |
#most_rated_by_authorities(limit = 1) ⇒ Object
12 13 14 |
# File 'lib/acts_as_mongo_rateable/acts_as_mongo_rateable.rb', line 12 def (limit=1) all({:order => "rating_stats.sum_of_weights DESC", :limit => limit}) end |