module Mongoid::TaggableWithContext::AggregationStrategy::RealTime::ClassMethods
Public Instance Methods
aggregation_collection_for(context)
click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time.rb, line 21 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/real_time.rb, line 17 def aggregation_database_collection_for(context) (@aggregation_database_collection ||= {})[context] ||= Mongo::Collection.new(self.collection.database, aggregation_collection_for(context)) end
recalculate_all_context_tag_weights!()
click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time.rb, line 35 def recalculate_all_context_tag_weights! tag_contexts.each do |context| recalculate_tag_weights!(context) end end
recalculate_tag_weights!(context)
click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time.rb, line 41 def recalculate_tag_weights!(context) db_field = self.class.tag_options_for(context)[:db_field] map = <<-END function() { if (!this.#{db_field})return; for (index in this.#{db_field}) emit(this.#{db_field}[index], 1); } END reduce = <<-END function(key, values) { var count = 0; for (index in values) count += values[index]; return count; } END self.class.map_reduce(map, reduce).out(replace: aggregation_collection_for(context)).time end
tag_name_attribute()
click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time.rb, line 11 def tag_name_attribute "_id" end