Abdulaziz Alsubaie
Abdulaziz Alsubaie

Reputation: 720

active record contains query

how can I implement "contains function" in active records? I am trying to query my database which contains the following data as an example

brand: ipad model : ipad 3gen specs : wifi+3g 32 GB black

when the user searched for "ipad black 3gen" he should get the above record.

this is my trail which didnt work

    @products = Product.where("brand like ? OR generation like ? OR spec_overview like ? ", "%"+params[:query].capitalize+"%", "%"+params[:query].capitalize+"%", "%"+params[:query].capitalize+"%")

Upvotes: 0

Views: 633

Answers (1)

x1a4
x1a4

Reputation: 19496

Sql is not a great fit for this type of query. You can do it with a fulltext index probably, but using something like Solr would be much less painful, and more accurate. You can integrate Solr into a Rails app with sunspot if you decide to go that direction.

Upvotes: 1

Related Questions