Reputation: 329
I'm using pg-search to search in a model. The problem I'm having is if I search for keywords that are in one field or the other it works but if I enter keywords that I know are in the 2 fields I'm using it's not returning anything.
Here is my search
@providers = Provider.text_search(params[:query])
and here is the helper
def self.text_search(query)
if query.present?
where("address @@ :q or conditions @@ :q", q: "%#{query}%")
else
scoped
end
end
To summarize... if I enter 2 keywords for address (ie: zipcode and street name) or 2 keywords for condition (ie: brand new) it works but if I enter a zip code and new in the search field it does not return anything
here is the query
Provider Load (1.3ms) SELECT "providers".* FROM "providers" WHERE (address @@ '%new rancho%' or conditions @@ '%new rancho%')
EDIT I forgot to post the pg_search_scope
pg_search_scope :search, against: [:address, :conditions], using: { tsearch: { dictionary: "english", prefix: true, any_word: true} }
Upvotes: 1
Views: 1732
Reputation: 7043
Try something like this in your model
include PgSearch
pg_search_scope :search, against: [:zipcode, :streetname],
using: {tsearch: {prefix: true, any_word: true}}
def self.text_search(query)
if query.present?
search(query)
else
scoped
end
end
Upvotes: 3