# Advance search using pg\_search gem passing three, two, one o nome parameters

**URL:** <https://www.ruby-forum.com/t/advance-search-using-pg-search-gem-passing-three-two-one-o-nome-parameters/225441>\
**Category:** Rails\
**Created:** [January 8, 2013, 11:59pm UTC](https://www.ruby-forum.com/t/advance-search-using-pg-search-gem-passing-three-two-one-o-nome-parameters/225441 "2013-01-08T23:59:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [January 8, 2013, 11:59pm UTC](https://www.ruby-forum.com/t/advance-search-using-pg-search-gem-passing-three-two-one-o-nome-parameters/225441/1 "2013-01-08T23:59:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/fbc32d/32.png) [@jean](https://www.ruby-forum.com/u/jean)\
**Post date:** [March 3, 2013, 9:23pm UTC](https://www.ruby-forum.com/t/advance-search-using-pg-search-gem-passing-three-two-one-o-nome-parameters/225441/2 "2013-03-03T21:23:38Z")

</div>

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
