Skip to main content

SQL for search

General • Asked by Robert Hopman
Hi Chris,

I had a question, solved it, now I'm looking for your feedback. For readability I use `a` in the example below:

a = params[:query]
Item.where("name ILIKE ? OR tagline ILIKE ? OR details ILIKE ?", "%#{a}%", "%#{a}%", "%#{a}%")

Do you have a similar query on gorails search for episode titles and forum thread titles?

Hey Robert!

I actually use Ransack to take care of this for me, but it's doing basically exactly that. I make two queries when you search, one for episodes, one for forum threads and then just display them in the autocomplete.

Eventually I might switch to ElasticSearch, but it requires a lot of RAM and probably wouldn't be a huge improvement to the search results anyways. 

ransack is great!  


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.