Make search cache order aware & accept values instead of column names
This commit is contained in:
@@ -7,19 +7,20 @@ module SearchCache
|
||||
|
||||
def calculate_tsvector
|
||||
ActiveRecord::Base.connection.execute("
|
||||
UPDATE proposals SET tsv = (to_tsvector('spanish', #{fields_to_sql})) WHERE id = #{self.id}")
|
||||
UPDATE proposals SET tsv = (#{searchable_values_sql}) WHERE id = #{self.id}")
|
||||
end
|
||||
|
||||
def fields_to_sql
|
||||
fields.collect { |field| "coalesce(#{field},'')" }.join(" || ' ' || ")
|
||||
private
|
||||
|
||||
def searchable_values_sql
|
||||
cx = ActiveRecord::Base.connection
|
||||
arr = []
|
||||
searchable_values.each do |val, weight|
|
||||
if val.present?
|
||||
arr << "setweight(to_tsvector('spanish', coalesce(#{cx.quote(val)}, '')), #{cx.quote(weight)})"
|
||||
end
|
||||
end
|
||||
arr.join(" || ")
|
||||
end
|
||||
|
||||
def fields
|
||||
searchable_fields << tags_to_sql
|
||||
end
|
||||
|
||||
def tags_to_sql
|
||||
"\'#{tag_list.join(' ')}\'"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user