module Mongoid::TaggableWithContext::AggregationStrategy::MapReduce::ClassMethods

Public Instance Methods

aggregation_collection_for(context) click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb, line 17
def aggregation_collection_for(context)
  "#{collection_name}_#{context}_aggregation"
end
aggregation_database_collection_for(context) click to toggle source

Collection name for storing results of tag count aggregation

# File lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb, line 13
def aggregation_database_collection_for(context)
  (@aggregation_database_collection ||= {})[context] ||= Mongo::Collection.new(self.collection.database, aggregation_collection_for(context))
end
tags_for(context, conditions={}) click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb, line 21
def tags_for(context, conditions={})
  aggregation_database_collection_for(context).find({value: {"$gt" => 0 }}).sort(_id: 1).to_a.map{ |t| t["_id"] }
end
tags_with_weight_for(context, conditions={}) click to toggle source

retrieve the list of tag with weight(count), this is useful for creating tag clouds

# File lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb, line 27
def tags_with_weight_for(context, conditions={})
  aggregation_database_collection_for(context).find({value: {"$gt" => 0 }}).sort(_id: 1).to_a.map{ |t| [t["_id"], t["value"].to_i] }
end