Module: Mongoid::TaggableWithContext::AggregationStrategy::MapReduce::ClassMethods
- Defined in:
- lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb
Instance Method Summary collapse
- #aggregation_collection_for(context) ⇒ Object
-
#aggregation_database_collection_for(context) ⇒ Object
Collection name for storing results of tag count aggregation.
- #tags_for(context, conditions = {}) ⇒ Object
-
#tags_with_weight_for(context, conditions = {}) ⇒ Object
retrieve the list of tag with weight(count), this is useful for creating tag clouds.
Instance Method Details
#aggregation_collection_for(context) ⇒ Object
17 18 19 |
# 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) ⇒ Object
Collection name for storing results of tag count aggregation
13 14 15 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb', line 13 def aggregation_database_collection_for(context) (@aggregation_database_collection ||= {})[context] ||= Moped::Collection.new(self.collection.database, aggregation_collection_for(context)) end |
#tags_for(context, conditions = {}) ⇒ Object
21 22 23 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb', line 21 def (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 = {}) ⇒ Object
retrieve the list of tag with weight(count), this is useful for creating tag clouds
27 28 29 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/map_reduce.rb', line 27 def (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 |