Skip to content

Support scopes in multi_search #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2025

Conversation

ellnix
Copy link
Contributor

@ellnix ellnix commented Mar 13, 2025

Pull Request

Related issue

Fixes part of #397

  • This makes multi_search, like the regular search, support relations and other collections that respond to where.
  • In favor of this new :collection option, :class_name is softly deprecated for a consistent user experience (since :collection does everything that :class_name did and more)

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.62%. Comparing base (b5d918f) to head (0d7480a).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #405      +/-   ##
==========================================
+ Coverage   89.56%   89.62%   +0.06%     
==========================================
  Files          13       13              
  Lines         776      781       +5     
==========================================
+ Hits          695      700       +5     
  Misses         81       81              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ellnix
Copy link
Contributor Author

ellnix commented Mar 13, 2025

@pozelli Please review and see if this makes multi_search behave how you expect it to 😄

@wesharper If you are interested in doing code review please take a look at this PR. (if you are not interested that's OK, it's not an assignment 😆 think of it more like a +cc)

@ellnix ellnix force-pushed the multi_search_collections branch 2 times, most recently from f7dcae3 to d969d9b Compare March 14, 2025 19:26
@pozelli
Copy link

pozelli commented Mar 14, 2025

@pozelli Please review and see if this makes multi_search behave how you expect it to 😄

Sure.

This PR addresses these items from #397:

Currently, multi_search (e.g., in FederatedSearchResult) does not seem to support queries on collections. It only works with models or simple indexes.

In a federated search, since it is not possible to use collections but only models or simple indexes, I must first perform an additional step: Queries to retrieve the IDs of each record.

This extra query could already be avoided if federated search supported collections, just as simple search does.

On the other hand:

However, we would still face the pagination issue.

I have tested the PR, and it works as I expected it to.

README.md Outdated
'books' => { q: 'Harry', class_name: 'Book' },
'mangas' => { q: 'Attack', class_name: 'Manga' }
# Collection may be a relation
'books' => { q: 'Harry', collection: Book.all },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't know about this name, I would vote for scope or model I'm not sure if collection is the term I hear the most when I'm talking/working about AR models.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:scope is something I considered, felt like it was at least as good as collection. I think that the name :scope has the expectation that you could pass a symbol to it and it would call that (Rails) scope on the model. I would like to do that but it's not possible without already knowing the model specified in another param which would overcomplicate everything.

I don't think model would be accurate since this is (in most cases) a Relation. I'll go ahead and rename to scope.

brunoocasali
brunoocasali previously approved these changes Mar 19, 2025
Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a remark about the name of the param but apart from that looks great!

@brunoocasali brunoocasali added the enhancement New feature or request label Mar 19, 2025
@ellnix
Copy link
Contributor Author

ellnix commented Mar 19, 2025

Rebased to deal with conflicts, the review is stale now @brunoocasali

@ellnix ellnix mentioned this pull request Mar 19, 2025
4 tasks
@ellnix ellnix changed the title Support collections in multi_search Support scopes in multi_search Mar 19, 2025
@ellnix ellnix requested a review from brunoocasali March 19, 2025 15:20
Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great addition, thanks @ellnix for the awesome work as usual 👏

@ellnix
Copy link
Contributor Author

ellnix commented Mar 24, 2025

bors merge

@ellnix ellnix closed this Mar 24, 2025
@meili-bors meili-bors bot merged commit 9d110f8 into meilisearch:main Mar 24, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants