Using proper SQL query to search for multiple search words.

This commit is contained in:
Christoph Haas 2013-08-08 22:32:20 +02:00
parent ee530072eb
commit d1d4cea63a

View file

@ -12,7 +12,9 @@ class Package < ActiveRecord::Base
RANK
# Do the full-text search and return results by rank
where("packages.name @@ :q or packages.description @@ :q", q: query).order("#{rank} desc")
where("to_tsvector('english', packages.name) @@ plainto_tsquery(:q) or
to_tsvector('english', packages.description) @@ plainto_tsquery(:q)
", q: query).order("#{rank} desc")
else
scoped
end