meilisearch / meilisearch/meilisearch-ruby

Scopes don't work as expected with limits

Open
#694 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
224
Forks
54
PR merge metrics
No merged PRs in 30d

Description

Description

When searching on a scope, first a a query to meilisearch is made, including the custom or default limit, only returning a small subset of the results. Only after that is the AR scope applied, which in many cases leads to too few or no matches even though there would be many records fulfilling both constraints.

I can understand that this might be hard or impossible to implement properly, but it seems like enough of a gotcha that the docs should explain the limitation. I think one workaround is just setting the limit very high, but of course that has performance implications. I don't know if there is a better solution.

Expected behavior

I expect the limit to be applied to the collection matching both the search and the scope

Current behavior

The limit is applied to a search not considering the scope, leading to way fewer records being returned than would actually match.

Environment

Dont think this is dependent on the environment:

    meilisearch (0.32.0)
      httparty (~> 0.22)
    meilisearch-rails (0.16.0)
      meilisearch (~> 0.32.0)
      mutex_m (~> 0.2)
Reproduction script:

I think any meiliserach setup would behave in this way, I hope this example is good enough to work with:

User.where(created_at: 1.week.ago..).search('Max')
Meilisearch::Rails.federated_search(queries: [{ q: 'Max', scope: User.where(created_at: 1.week.ago) }])

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing documentation for scopes, search limits, and federated_search, then reproduce the behavior with the provided User.where(...).search('Max') and federated_search examples. Document that the limit is applied before the scope, explain the resulting incomplete matches, and note the high-limit workaround and its performance implications.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.