From 5837c3ac9443bd34291ea468177e0f7582bf4219 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 18 Feb 2016 17:11:48 +0100 Subject: [PATCH] uses standard search to create proposal summaries --- app/models/proposal.rb | 13 ++++++------- config/initializers/acts_as_taggable_on.rb | 4 ---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index bb4c5458b..3bd1d9a72 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -42,7 +42,6 @@ class Proposal < ActiveRecord::Base scope :sort_by_relevance , -> { all } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} - scope :in_categories, -> { where("tags.id IN (?)", ActsAsTaggableOn::Tag.category_ids) } def searchable_values { title => 'A', @@ -71,12 +70,12 @@ class Proposal < ActiveRecord::Base end def self.for_summary - last_week. - sort_by_confidence_score. - in_categories. - joins(:tags). - select('proposals.*, tags.name as tag_name'). - group_by(&:tag_name) + summary = {} + categories = ActsAsTaggableOn::Tag.category_names + categories.each do |category| + summary[category] = search(category).last_week.sort_by_confidence_score.limit(3) + end + summary end def description diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index d4f6e1099..c9e38683c 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -38,10 +38,6 @@ module ActsAsTaggableOn Tag.where("kind = 'category'").map {|tag| tag.name.downcase } end - def self.category_ids - Tag.where("kind = 'category'").map {|tag| tag.id } - end - private def custom_counter_field_name_for(taggable_type) "#{taggable_type.underscore.pluralize}_count"