Hi, How do you use Tsearch2 in Rails? Petr -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
straightflush-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-24 22:52 UTC
Re: Postgres and Tsearch2, how do you do it?
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 On 10/23/06, Petr <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > How do you use Tsearch2 in Rails? > > Petr > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---