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_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

View File

@@ -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"