nitc :: StarRatingRepo :: defaultinit
# StarRating Mongo Repository
class StarRatingRepo
super MongoRepository[StarRating]
# Find most rated mentities
fun most_rated: Array[JsonObject] do
var pipeline = new MongoPipeline
pipeline.group((new MongoGroup("$mentity")).sum("count", 1))
pipeline.sort((new MongoMatch).eq("count", -1))
pipeline.limit(10)
return collection.aggregate(pipeline)
end
# Find best rated mentities
fun best_rated: Array[JsonObject] do
var pipeline = new MongoPipeline
pipeline.group((new MongoGroup("$mentity")).avg("avg", "$rating"))
pipeline.sort((new MongoMatch).eq("avg", -1))
pipeline.limit(10)
return collection.aggregate(pipeline)
end
# Find worst rated mentities
fun worst_rated: Array[JsonObject] do
var pipeline = new MongoPipeline
pipeline.group((new MongoGroup("$mentity")).avg("avg", "$rating"))
pipeline.sort((new MongoMatch).eq("avg", 1))
pipeline.limit(10)
return collection.aggregate(pipeline)
end
# Find worst rated mentities
fun users_ratings: Array[JsonObject] do
var pipeline = new MongoPipeline
pipeline.group((new MongoGroup("$user")).sum("count", 1))
pipeline.sort((new MongoMatch).eq("count", -1))
pipeline.limit(10)
return collection.aggregate(pipeline)
end
end
src/doc/api/api_feedback.nit:248,1--287,3