Jean
2013-Jan-08 22:57 UTC
advance search using pg_search gem passing three, two, one o nome parameters.
Hello I trying this search
pg_search_scope :advance_search, against: [:title, :place, :category],
using: { tsearch: { dictionary: "spanish"} }
def self.searchadv(title, place, category)
advance_search(:title => title, :place => place, :category =>
category)
end
I could not make this work, I always get cero records, but I have records
with the parameters I''m passing. By the way no all the parameter need
to be
present in the passing, for example I can search just using the title, o
title and place or place or category or all together.
Thanks for your help, I really need it.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/MOl1Qb3Dyp4J.
For more options, visit https://groups.google.com/groups/opt_out.
Grant Hutchins
2013-Mar-03 20:21 UTC
Re: advance search using pg_search gem passing three, two, one o nome parameters.
Hi Jean, sorry for the late reply.
When you create a search method using pg_search_scope, it takes only one
parameter, a string query.
So for your example, you should not pass a Hash into your advance_search
method.
Instead, imagine a user wants to find things with the title "Moby
Dick" in
the place "Paris" with the category "Novel". They could type
into a search
box the single string "moby dick paris novel" and you could call
advance_search this way:
advance_search("moby dick paris novel")
or
advance_search(params[:query]) # this assumes you are in a Rails
controller and you have a form that submits a param named "query"
If you are trying to search separately by different fields, then pg_search
is not the correct solution. You could try something like this:
def self.searchadv(title, place, category)
where(:title => title, :place => place, :category => category)
end
But that will only find exact matches. Doing something more advanced than
this is an exercise for the reader.
Grant
On Tuesday, January 8, 2013 5:57:48 PM UTC-5, Jean
wrote:>
> Hello I trying this search
>
> pg_search_scope :advance_search, against: [:title, :place, :category],
> using: { tsearch: { dictionary: "spanish"} }
>
>
> def self.searchadv(title, place, category)
> advance_search(:title => title, :place => place, :category =>
> category)
> end
>
> I could not make this work, I always get cero records, but I have records
> with the parameters I''m passing. By the way no all the parameter
need to be
> present in the passing, for example I can search just using the title, o
> title and place or place or category or all together.
>
> Thanks for your help, I really need it.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/gVIZmv1LF74J.
For more options, visit https://groups.google.com/groups/opt_out.