Skip to content
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

Support Multi-Search #321

Merged
merged 8 commits into from
Feb 27, 2024
Merged

Conversation

ellnix
Copy link
Collaborator

@ellnix ellnix commented Feb 9, 2024

Pull Request

Related issue

Fixes #254

I thought I'd make a draft PR to discuss and review API decisions. I discussed the method signature of a theoretical multi_search in #254 (comment), if there is no problem I will proceed with this one:

MeiliSearch::Rails.multi_search(
  'book_production' => {q: 'paper', class_name: 'Book', **book_options}, # Index with a model
  Product => {q: 'thing', **product_options}, # Model with implied index
  'blurbs' => { q: 'happy' }, # Index not backed by a model, results will be simple hashes
  **other_searches
)

Initially I expected that the return type would be a simple array, however this might not be ideal since it

  • does not provide a performant way to use only the results of a single search
  • does not provide a way to access search metadata provided by meilisearch

I am thinking of either a simple hash or a hash-like class with convenience methods.

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: Patch coverage is 97.36842% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 90.22%. Comparing base (b0bfab1) to head (9c186c9).

Files Patch % Lines
lib/meilisearch/rails/multi_search/result.rb 95.55% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   89.47%   90.22%   +0.75%     
==========================================
  Files          11       13       +2     
  Lines         684      757      +73     
==========================================
+ Hits          612      683      +71     
- Misses         72       74       +2     

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

@ellnix ellnix force-pushed the support-multi-search branch 3 times, most recently from 6222e8e to 1eb2b84 Compare February 12, 2024 15:33
@ellnix ellnix marked this pull request as ready for review February 12, 2024 15:39
Copy link
Collaborator Author

@ellnix ellnix left a comment

Choose a reason for hiding this comment

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

Should be ready for review (but I don't think it should be merged in this state), please see the comments I left.

lib/meilisearch/rails/multi_search/result.rb Show resolved Hide resolved
lib/meilisearch/rails/multi_search/result.rb Show resolved Hide resolved

private

def load_results(klass, result)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need some guidance on how pagination would be expected to work in multi search.
Paginate the results of each search, paginate the search as a whole, or both? Waiting on a review before going through with a solution.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I know and per the docs: https://www.meilisearch.com/docs/reference/api/multi_search

You handle the pagination by each "block" of returned data. Because essentially the multi_search is just a way of making multiple requests at once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That checks out, since each search can have its own pagination options. This would mean that displaying all of the results together would not make much sense, since they would never be on the same "page".

Perhaps I should expect that #each_result should be the main way to use a MultiSearchResult? It might make most sense in the documentation.

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I am quite unsure about how the users are going to make use of this feature, so I would prefer to have some external output before applying more changes to it. But I'm on your side to whichever option you may prefer.

module MeiliSearch
module Rails
class << self
def multi_search(searches)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Placed the multi search method as MeiliSearch::Rails.multi_search for the time being, but it does not feel like we should expect our users to write it all out.

Maybe ApplicationRecord.multi_search, or give all models the same, generic, multi_search method?

Copy link
Member

Choose a reason for hiding this comment

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

I think for convenience, we could add it to ApplicationRecord indeed.

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.

I think it is a good starting point to have this feature on rails!

I made some comments, let me know if you agree with them

lib/meilisearch/rails/multi_search.rb Outdated Show resolved Hide resolved

private

def load_results(klass, result)
Copy link
Member

Choose a reason for hiding this comment

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

As far as I know and per the docs: https://www.meilisearch.com/docs/reference/api/multi_search

You handle the pagination by each "block" of returned data. Because essentially the multi_search is just a way of making multiple requests at once.

spec/multi_search_spec.rb Outdated Show resolved Hide resolved
spec/multi_search/result_spec.rb Show resolved Hide resolved
@brunoocasali brunoocasali added the enhancement New feature or request label Feb 14, 2024
@brunoocasali brunoocasali self-requested a review February 15, 2024 19:46
brunoocasali
brunoocasali previously approved these changes Feb 19, 2024
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.

LGTM!

@curquiza
Copy link
Member

@ellnix merge when you want 😊

@ellnix
Copy link
Collaborator Author

ellnix commented Feb 23, 2024

@ellnix merge when you want 😊

I do not think this is ready yet, I have to implement Bruno's suggestions and also some things I left out myself, for instance it's still not tested for MongoDB and Sequel.

@curquiza
Copy link
Member

I was confused by the LGTM of Bruno 😄

@brunoocasali
Copy link
Member

Hey @ellnix I thought we were ok with releasing like this, most of my suggestions are not logic-related but style ones.

Plus about this comment:

"for instance it's still not tested for MongoDB and Sequel."

I'm not even sure we still can say that we support MongoDB in the first place, there is no "real" test coverage for MongoDB.
So I don't think you need to make this PR wait if you see it is not working for mongo (we could work on that later)

@ellnix
Copy link
Collaborator Author

ellnix commented Feb 26, 2024

I'm not even sure we still can say that we support MongoDB in the first place, there is no "real" test coverage for MongoDB. So I don't think you need to make this PR wait if you see it is not working for mongo (we could work on that later)

Yeah, I thought I could somehow test them but that was my bad. Anyway the other changes I wanted to be done are done, this is ready to merge if it looks good to you now that pagination is implemented.

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.

It should be good now, with the pagination :)

I didn't try locally, but looking closely to the tests, they seem good enough!

LGTM

@ellnix
Copy link
Collaborator Author

ellnix commented Feb 27, 2024

bors merge

@ellnix ellnix closed this Feb 27, 2024
@meili-bors meili-bors bot merged commit b5983bd into meilisearch:main Feb 27, 2024
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.

Perform multiple searches in one single HTTP request
3 participants