From fa83e196caf74ed874717d9a576a6f807a180a33 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 17 Nov 2015 23:20:18 +0100 Subject: [PATCH] adds tags to tsvector --- app/models/proposal.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 60ef20420..84718a5d2 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -58,17 +58,21 @@ class Proposal < ActiveRecord::Base order_within_rank: "proposals.created_at DESC" } - #remember to add tags.name def searchable_fields - %w(title question summary description) + %w(title question summary description) << tags_to_sql end - def searchable_fields_to_sql + def tags_to_sql + "\'#{tag_list.join(' ')}\'" + end + + def searchable_content searchable_fields.collect { |field| "coalesce(#{field},'')" }.join(" || ' ' || ") end def calculate_tsvector - ActiveRecord::Base.connection.execute("UPDATE proposals SET tsv = (to_tsvector('spanish', #{searchable_fields_to_sql})) WHERE id = #{self.id}") + ActiveRecord::Base.connection.execute(" + UPDATE proposals SET tsv = (to_tsvector('spanish', #{searchable_content})) WHERE id = #{self.id}") end def description