Postgres and Tsearch2, how do you do it?

Hi,
How do you use Tsearch2 in Rails?

Petr

i had a classifieds table with 2 columns (title and description) that i
wanted to include in my search. Here is how i created it


alter table classifieds add column search_idx tsvector ;
update classifieds set
search_idx=to_tsvector(‘default’,coalesce(title,’’)
|| ’ ’ || coalesce(description,’’)) ;
create index classifieds_search_idx on classifieds using
gist(search_idx) ;
vacuum full analyze ;
create trigger tsvectorupdate BEFORE UPDATE OR INSERT on classifieds for
each row execute procedure tsearch2(search_idx,title,description) ;

then in my model did this passing in search terms as a parameter

def self.fs_search(q)
ts_query = q.gsub(/[\s+]/,’&’)
self.find_by_sql([“select * from classifieds where search_idx @@
to_tsquery(‘default’,?)”,ts_query])
end

good luck.

Adam