Skip to main content

Search Filters/Report Generator

Rails • Asked by RJ McCollam

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?


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.


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

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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ 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.