Skip to main content

Search all models gem

Gems / Libraries • Asked by Ali Rizvi

I have seen this done in other rails application where you can search for a term and it would search across multiple models and return results from each. What is the best gem to use for this purpose?

Is there a episode in GoRails for Searching and Filtering?

Regards,
Ali


Searchkick with Elasticsearch is pretty good for searching models and is very flexible. It's my go-to solution with searching.

Here's an episode on Searchkick
https://gorails.com/episodes/elasticsearch-with-searckick?autoplay=1

You could also look into using Ransack I believe is another popular gem for it.


Like Andrew said, Searchkick is perfect for this. Each model gets an index inside ElasticSearch and then searchkick lets you query over those by simply doing this: https://github.com/ankane/searchkick#multiple-indices All that should make sense after watching the screencast. 😎

Ransack isn't quite the same in that it doesn't index them in a way that you could search multiple models together. You'd actually have to search each table separately and then combine the results in your view. It's nothing fancy as it just does database queries which makes it really easy to implement without any separate services, but more rudimentary in a sense.


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.