-
Notifications
You must be signed in to change notification settings - Fork 46
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
Federated search added #567
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #567 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 737 737
=========================================
Hits 737 737 ☔ View full report in Codecov by Sentry. |
b2749b1
to
d5f6edd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Good job on the documentation comment, we should add those for the entire gem.
A few things regarding git:
- Try to write commit messages in imperative sentences
Federated search added
❌
Add federated search
✔️ - Use git rebase to clean up the git history.
If you are new to git or unsure how to do this, feel free to reach out to me.
@@ -16,4 +16,19 @@ | |||
expect(response['results'][0]['estimatedTotalHits']).to eq(0) | |||
expect(response['results'][1]['estimatedTotalHits']).to eq(0) | |||
end | |||
|
|||
it 'does a federated search with two different indexes' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this test is sufficient to see that the server has indeed understood that this is a federated search and not a regular multi-search, there should be separate tests to see if the server returns what you would expect under these circumstances.
In addition we should check that limit and offset are sent properly and work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that meet your expectations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, from what I understood here @Nymuxyzo you would need to make two tests:
- one asserting the inexistence of the presence of the param federation in the response
- one asserting that you explicitly called the
multi_search
with a federation request, since the doc says a non-null value the value could bemulti_search(data, federation: true, federation_options: {....}) # where federation options are not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brunoocasali I'm sorry, but I don't understand the statement. When I look at the added test in the PHP SDK (tests/Endpoints/MultiSearchTest.php), I recognize my pattern to a very large extent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would very much like to bring this issue to a good end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also read and reread
one asserting the inexistence of the presence of the param federation in the response
one asserting that you explicitly called the multi_search with a federation request, since the doc says a non-null value the value could be multi_search(data, federation: true, federation_options: {....}) # where federation options are not required
and I'm sorry @brunoocasali I can't make sense of it xD
I think this might be a typo:
one asserting the inexistence
ofor the presence of the param federation in the response
but the presence of _federation
is already looked for in the test.
Meanwhile this:
multi_search(data, federation: true, federation_options: {....}) # where federation options are not required
I'm not sure I'm following with the distinction between federation
and federation_options
, there is only one federation
option, which can either be an object of options or a truthy value to enable it with defaults.
In any case, this should work fine as long as we don't mess with it, ruby is dynamically typed and there is nothing preventing someone from passing a boolean as federation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, @ellnix, I agree with your previous message; I will point out the change in another comment.
da76a89
to
77ed25b
Compare
Commit message rewritten and git rebase executed |
77ed25b
to
83a79c8
Compare
@@ -16,4 +16,19 @@ | |||
expect(response['results'][0]['estimatedTotalHits']).to eq(0) | |||
expect(response['results'][1]['estimatedTotalHits']).to eq(0) | |||
end | |||
|
|||
it 'does a federated search with two different indexes' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, from what I understood here @Nymuxyzo you would need to make two tests:
- one asserting the inexistence of the presence of the param federation in the response
- one asserting that you explicitly called the
multi_search
with a federation request, since the doc says a non-null value the value could bemulti_search(data, federation: true, federation_options: {....}) # where federation options are not required
8e87707
to
37bb760
Compare
@ellnix can you make the last test to ensure the federation is working? |
37bb760
to
7e15ead
Compare
7e15ead
to
62ccd9d
Compare
62ccd9d
to
6b51188
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for taking so long to get to this, I spent quite a lot of time reading and rereading what happened in this thread and the reference in the meilisearch documentation.
There is also a code sample that the issue of this PR does not mention for some reason (this example is from meilisearch-js):
multi_search_federated_1: |-
client.multiSearch({
federation: {},
queries: [
{
indexUid: 'movies',
q: 'batman',
},
{
indexUid: 'comics',
q: 'batman',
},
]
})
if you would like to add it, it's not a big deal if you would like to focus strictly on the code.
Please don't hesitate to reach out to me if I said something stupid (chances are I did). I'm also on the meilisearch discord server under the same name, feel free to add me 😄
# @param [Hash] federation_options | ||
# - `limit`: number of results in the merged list | ||
# - `offset`: number of results to skip in the merged list | ||
def multi_search(data, federation_options = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan personally of two positional arguments with almost no explanation as to what each of them does in the non-existent documentation. Especially since in the reference, federation is listed first (I'm guessing it's alphabetical)
I would prefer if we took the js approach and used query:
and federation:
keyword arguments.
This would mean breaking code that was written to use multi_search before this PR. But, we can avoid that if we have one data=nil
positional argument which we take as a query, and warn the user on its use:
def foo(bad_arg=nil, query: {}, federation: nil)
if bad_arg
puts "Bad arg is bad!"
end
query.update(bad_arg)
{
query: query,
federation: federation
}
end
foo({ q: 'hello world'}, federation: true)
# Bad arg is bad!
# => {:query=>{:q=>"hello world"}, :federation=>true}
Obviously, please don't use puts
(Utils.soft_deprecate!
might be appropriate) to throw warnings, and name the arguments appropriately if you choose to do this.
@@ -16,4 +16,19 @@ | |||
expect(response['results'][0]['estimatedTotalHits']).to eq(0) | |||
expect(response['results'][1]['estimatedTotalHits']).to eq(0) | |||
end | |||
|
|||
it 'does a federated search with two different indexes' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also read and reread
one asserting the inexistence of the presence of the param federation in the response
one asserting that you explicitly called the multi_search with a federation request, since the doc says a non-null value the value could be multi_search(data, federation: true, federation_options: {....}) # where federation options are not required
and I'm sorry @brunoocasali I can't make sense of it xD
I think this might be a typo:
one asserting the inexistence
ofor the presence of the param federation in the response
but the presence of _federation
is already looked for in the test.
Meanwhile this:
multi_search(data, federation: true, federation_options: {....}) # where federation options are not required
I'm not sure I'm following with the distinction between federation
and federation_options
, there is only one federation
option, which can either be an object of options or a truthy value to enable it with defaults.
In any case, this should work fine as long as we don't mess with it, ruby is dynamically typed and there is nothing preventing someone from passing a boolean as federation
.
body = Utils.transform_attributes(data) | ||
|
||
http_post '/multi-search', queries: body | ||
http_post '/multi-search', queries: body, federation: federation_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
federation_options
should be transformed to camel case with Utils.transform_attributes
.
To be clear, it wasn't necessary when you first started this PR, but now there are 2 new options (facetsByIndex
and mergeFacets
) which won't work if you pass them as snake_cased symbols.
limit: 20, | ||
offset: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if these values were not the same as the defaults, but it's not a big problem.
# @param [Hash] federation_options | ||
# - `limit`: number of results in the merged list | ||
# - `offset`: number of results to skip in the merged list | ||
def multi_search(data, federation_options = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, basically what @ellnix suggested is to do something like:
def multi_search(data, federation_options = nil) | |
def multi_search(data, federation: nil) |
and I agree with that :)
Pull Request
Related issue
Fixes #558
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements: