module Mongoid::TaggableWithContext::AggregationStrategy::RealTimeGroupBy::ClassMethods

Public Instance Methods

tag_name_attribute() click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb, line 7
def tag_name_attribute
  "_name"
end
tags_for(context, group_by, conditions={}) click to toggle source
Calls superclass method
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb, line 11
def tags_for(context, group_by, conditions={})
  results = if group_by
    query(context, group_by).to_a.map{ |t| t[tag_name_attribute] }
  else
    super(context, conditions)
  end
  results.uniq
end
tags_with_weight_for(context, group_by, conditions={}) click to toggle source
Calls superclass method
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb, line 20
def tags_with_weight_for(context, group_by, conditions={})
  results = if group_by
    query(context, group_by).to_a.map{ |t| [t[tag_name_attribute], t["value"].to_i] }
  else
    super(context, conditions)
  end

  tag_hash = {}
  results.each do |tag, weight|
    tag_hash[tag] ||= 0
    tag_hash[tag] += weight
  end
  tag_hash.to_a
end

Protected Instance Methods

query(context, group_by) click to toggle source
# File lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb, line 36
def query(context, group_by)
  aggregation_database_collection_for(context).find({value: {"$gt" => 0 }, group_by: group_by}).sort(tag_name_attribute.to_sym => 1)
end