Ask A Question

Notifications

You’re not receiving notifications from this thread.

Search Filters/Report Generator

RJ McCollam asked in Rails

I am working on a project for a client that consists of a primary jobs model that has a number of forms (other models) within it.

I am needing to build out search functionality that searches through all models in order to return a job that matches. This search also needs to include filters with the ability to filter by client, time frame, and a couple other pieces of data.

In looking through possible solutions i think that the most recent video Chris did on elasticsearch with filters (https://gorails.com/episodes/search-filters-with-elasticsearch-aggregations) might be what I am after.

What I havent seen in the research I have done so far is searching through multiple models. Would elasticsearch with filters be a good option to accomplish what I am trying to?

Reply

hmm, try ransack.

https://www.youtube.com/watch?v=Vht9iCw8ApE

I'm using it , it's great if you don't want to go to the expensive of setting up a elastic search server.

Reply

You can search multiple models at once with Searchkick by doing the following:

Searchkick.search "milk", index_name: [Product, Category]

And you can also customize the search_data method on the model to include attributes from associated models.

This example builds up a string to index of all the tags stored in an association on the record.

  def search_data
    {
      name_tagged: "#{name} #{tags.map(&:name).join(" ")}"
    }
  end
Reply

Thanks Joe and Chris for both of your feedback. I decided to go with ElasticSearch and Searchkick since there seems to be more current documentation for what I am trying to accomplish.

Reply
Join the discussion
Create an account Log in

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

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

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