All threads / How to add Search in Rails using Meilisearch Discussion
Ask A Question


You’re not receiving notifications from this thread.

How to add Search in Rails using Meilisearch Discussion

Thank you, Chris.
Can we add aggregations in Meilisearch as we do in ElasticSearch?

Thanks for another great video! If I had a profile model that was inverse of the user model, would I have to do things different? Thanks

Another question. What's the best way to integrate pagy_search in to my index if I'm already using Pagy? In my controller I currently have:

def index

    @gold_drivers = Driver.gold_plan
    @silver_drivers = Driver.silver_plan
    @free_drivers = Driver.free_plan

    @pagy, @drivers = pagy_array(
      @gold_drivers + @silver_drivers + @free_drivers,
      page: params[:page],
      items: 16

    if params[:query].present?
      @drivers = @gold_drivers + @silver_drivers + @free_drivers
      drivers_search = Driver.pagy_search(params[:query])
      @pagy, @drivers = pagy_meilisearch(drivers_search, items: 25, page: params[:page])

I have a Driver model which delegate's to a Profile model. Unfortunately when I click search I get Driver#first_name delegated to profile.first_name, but profile is nil: #<Driver id: 224... as I know this driver does not have a profile, but the query run for @gold_drivers = Driver.gold_plan / @silver_drivers = Driver.silver_plan etc should not select a driver without a profile.

The query behind Driver.gold_plan is:

find_by_sql("SELECT drivers.*, (profiles.no_races + profiles.no_poles + profiles.no_podiums + profiles.no_wins)       AS scores FROM drivers INNER JOIN profiles ON profiles.driver_id = INNER JOIN subscriptions ON     subscriptions.driver_id = WHERE subscriptions.status = 'active' AND profiles.first_name != null OR     profiles.first_name != '' AND subscriptions.stripe_plan = '#{ENV["GOLD_ANNUAL"]}' OR subscriptions.stripe_plan =     '#{ENV["GOLD_MONTH"]}' GROUP BY scores, ORDER BY scores DESC")

In that query I'm using "AND profiles.first_name != null OR profiles.first_name != ''" which works in the pagy_page section - but not in the pagy_search section.

Any direction with this is appreciated!

Hi Chris, great video! How do you get to find multiple models with 1 query? I can see gorails search show lessons and forum threads, but can't get it working on my app.
Tried with create 1 custom index, but then I don't know how to get the pagy_search work (it depends on a model to query...).

Some clue on this??
Thanks in advance!

Great tutorial! But might want to point out that Meilisearch doesn't work with Heroku, or at least not currently.

As stated by the developer, Meilisearch stores data directly in disk, which is a no-go for deployment on Heroku.

Found this out after implemented a nice Meilisearch based search for a project. Oh well. 😭

Thoughts on how to use Meilisearch on Heroku?

Anyone else getting this error?

The request was not processed in the expected time. Failed to open TCP connection to localhost:7700 (execution expired)

Join the discussion

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

Join 70,078+ 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.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.