Answer the question
In order to leave comments, you need to log in
How to combine two where queries (from an array) into one?
I am doing a search (autocomplete), I need to find the name Tire TYUMEN 175/70 on request tire 175 .
I do with ILIKE
How to get a request like
SELECT "products".* FROM "products" WHERE (title ILIKE '%шина%') AND (title ILIKE '%175%')
? products = Product.all
["шина", "175"].each do |word|
products = products.where("title ILIKE ?", "%#{word}")
end
Product.all
, then get a requestSELECT "products".* FROM "products" WHERE (title ILIKE '%175')
SIMILAR TO
, but it doesn't work here either.
Answer the question
In order to leave comments, you need to log in
Harness the power of Arel table, <%=username%>
q = Product.arel_table[:title].matches_all(["шина", "175"])
products = Product.where(q)
like %...%
- it's a crutch.
Then you need to find "tire" by "tire".
Then, so that the "bus" is NOT "car".
Then - the ranking of the results.
And it will turn out to be shit code, which will only have to be thrown out entirely.
Why not just write right?
https://www.postgresql.org/docs/current/static/tex...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question