def self.tsearch(query,country)
query = query.gsub(/\(.*|'/){}.split.join('&')
find_by_sql("SELECT * from places WHERE country_id = #{country}
AND tsearchable @@ to_tsquery('#{query}');")
end
all you need with postgres 8.3:
class PlacesTsearch < ActiveRecord::Migration
def self.up
execute("ALTER TABLE places ADD COLUMN tsearchable tsvector;
UPDATE places SET tsearchable=to_tsvector('english',coalesce(title_ascii,''));
CREATE INDEX tsearchable_idx ON places USING gin(tsearchable);")
execute("VACUUM FULL ANALYZE;")
end
def self.down
remove_column :places, :tsearchable
end
end