All threads / Search all models gem

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Search all models gem

Ali Rizvi asked in Gems / Libraries

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.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.