Merge pull request #906 from consul/summary-results

uses standard search to create proposal summaries
This commit is contained in:
Juanjo Bazán
2016-02-18 17:29:48 +01:00
2 changed files with 6 additions and 11 deletions

View File

@@ -42,7 +42,6 @@ class Proposal < ActiveRecord::Base
scope :sort_by_relevance , -> { all } scope :sort_by_relevance , -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
scope :in_categories, -> { where("tags.id IN (?)", ActsAsTaggableOn::Tag.category_ids) }
def searchable_values def searchable_values
{ title => 'A', { title => 'A',
@@ -71,12 +70,12 @@ class Proposal < ActiveRecord::Base
end end
def self.for_summary def self.for_summary
last_week. summary = {}
sort_by_confidence_score. categories = ActsAsTaggableOn::Tag.category_names
in_categories. categories.each do |category|
joins(:tags). summary[category] = search(category).last_week.sort_by_confidence_score.limit(3)
select('proposals.*, tags.name as tag_name'). end
group_by(&:tag_name) summary
end end
def description def description

View File

@@ -38,10 +38,6 @@ module ActsAsTaggableOn
Tag.where("kind = 'category'").map {|tag| tag.name.downcase } Tag.where("kind = 'category'").map {|tag| tag.name.downcase }
end end
def self.category_ids
Tag.where("kind = 'category'").map {|tag| tag.id }
end
private private
def custom_counter_field_name_for(taggable_type) def custom_counter_field_name_for(taggable_type)
"#{taggable_type.underscore.pluralize}_count" "#{taggable_type.underscore.pluralize}_count"