Ask A Question

Notifications

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?

Reply

Thinking Sphinx is another great option.

Reply

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

Reply

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])
    end
  end

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 = drivers.id INNER JOIN subscriptions ON     subscriptions.driver_id = drivers.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, drivers.id 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!

Reply

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!

Reply

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

https://github.com/meilisearch/MeiliSearch/discussions/1092#discussioncomment-147780

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. 😭

Reply

Thoughts on how to use Meilisearch on Heroku?

Reply

Anyone else getting this error?

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

Reply

Any chance you can help us use meilisearch on render? (as I also followed Colin's render deploy video: https://gorails.com/episodes/how-to-deploy-rails-to-render?autoplay=1)

From what I gather, this must run on disk, and I've found this solution so far: https://github.com/Amrit0991/meilisearch-docker-render

Reply
Join the discussion
Create an account Log in

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

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

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