-
Notifications
You must be signed in to change notification settings - Fork 100
Add support for typo tolerance customization #351
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
Add support for typo tolerance customization #351
Conversation
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.
Hey @vishalsodani thanks for this contribution :)
Could you look at the specification? I think the parameters are optional
I know it was not part of the PR description, but could you add (or update) the following code-samples based on this example:
|
ok. I will add these. |
60667db
to
0674a1e
Compare
Can you please review? I have made the parameters optional. Is the implementation ok? |
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.
Very nice PR 🔥
|
Hi, I feel there is an issue with this API design. If I tun this test, the test fails `
We are setting |
Added. |
I have redesigned the API to use a builder pattern. So, a user is able to create a default object and can then set various attributes. |
@bidoubiwa Hi, I am done with all the changes. Please review. Thanks! |
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.
Hey @vishalsodani
We are setting enabled as None which should not be allowed. Am I correct?
Actually, you are right and just raised a bug in Meilisearch haha! See this spec
🔴 Sending a value with a different type than Boolean for the enabled field returns an bad_request error.
While I appreciate a lot that you made so many checks 🔥, They checks should be done at Meilisearch side and not ours. As, if we start going that path, we are basically re-writing the error handler of Meilisearch.
Meanwhile, for us, null
is accepted until fixed by Meilisearch in a next release.
Can you remove:
- default_as_true
- default_one_typo_size
- default_two_typos_size
- is_true
- is_default_for_one_typo
- is_default_for_two_typos
- is_min_word_size_object_default
ok. Should I also revert the builder pattern? It does not seem that useful now. |
Great! |
Yes probably it is best to keep consistency with the other nested settings like |
|
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.
In your code-samples, could you only add the fields that are required and removed the ones that are not? Example in comment.
let typo_tolerance = TypoToleranceSettings { | ||
enabled: Some(true), | ||
disable_on_attributes: Some(vec!["title".to_string()]), | ||
disable_on_words: Some(vec![]) |
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.
disable_on_words: Some(vec![]) |
The fields that are not required should not be added to the samples. Normally this should not raise an error, right?
assert_eq!(typo_tolerance, res); | ||
} | ||
|
||
#[meilisearch_test] |
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.
Can you add a test where you only send a partial object ?
for example:
- update only
enabled
- make the request, check if correct
let typo_tolerance = TypoToleranceSettings {
enabled: Some(false),
};
in the same test:
- update only
disabled_on_attributes
- make the request, check if both
enabled
anddisabled_on_attributes
still have the correct changes.
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 have to initialize all the fields of a struct. I cannot have a partial struct. Is it possible?
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.
`
missing structure fields:
- disable_on_attributes
- disable_on_words
- min_word_size_for_typos
`
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.
Oh yeah... I mixed up the languages. My bad. I guess there that's the reason for adding the builder pattern... If you don't mind can you add it? With all the default values set to None?
Very sorry about the mixup. A lot of context switches between languages😅
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.
If you look at this sample code https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d78d2a9f68131c270eadffb4df44d4a0; the changes I had made allowed for partial objects to be sent. The standard output shows -
Ok("{\"minWordSizeForTypos\":{\"oneTypo\":0},\"age\":10}")
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.
If you look at this sample code https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d78d2a9f68131c270eadffb4df44d4a0; the changes I had made allowed for partial objects to be sent. The standard output shows -
Ok("{\"minWordSizeForTypos\":{\"oneTypo\":0},\"age\":10}")
@bidoubiwa Please see the above sample code shared on playground.
This message is sent automatically Thanks again for contributing to Meilisearch ❤️ |
Hey @vishalsodani |
What's the state of this PR? We need this. |
impl Default for MinWordSizeForTypos { | ||
fn default() -> Self { | ||
MinWordSizeForTypos { | ||
one_typo: Some(5), | ||
two_typos: Some(9), | ||
} | ||
} | ||
} |
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.
We shouldn't try to guess the default value of meilisearch by default, + we don't want to overwrite a previous call of the route.
Sending None
is enough.
impl Default for MinWordSizeForTypos { | |
fn default() -> Self { | |
MinWordSizeForTypos { | |
one_typo: Some(5), | |
two_typos: Some(9), | |
} | |
} | |
} | |
impl Default for MinWordSizeForTypos { | |
fn default() -> Self { | |
MinWordSizeForTypos { | |
one_typo: None, | |
two_typos: None, | |
} | |
} | |
} |
impl Default for TypoToleranceSettings { | ||
fn default() -> Self { | ||
TypoToleranceSettings { | ||
enabled: Some(true), | ||
disable_on_attributes: Some(vec![]), | ||
disable_on_words: Some(vec![]), | ||
min_word_size_for_typos: Some(MinWordSizeForTypos::default()), | ||
} | ||
} | ||
} |
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.
Once again, no reason to force some settings when creating the default value.
impl Default for TypoToleranceSettings { | |
fn default() -> Self { | |
TypoToleranceSettings { | |
enabled: Some(true), | |
disable_on_attributes: Some(vec![]), | |
disable_on_words: Some(vec![]), | |
min_word_size_for_typos: Some(MinWordSizeForTypos::default()), | |
} | |
} | |
} | |
impl Default for TypoToleranceSettings { | |
fn default() -> Self { | |
TypoToleranceSettings { | |
enabled: None, | |
disable_on_attributes: None, | |
disable_on_words: None, | |
min_word_size_for_typos: None, | |
} | |
} | |
} |
@irevoire, the original author hasn't had any activity on GitHub since then. |
480: Add support for typo tolerance customization r=bidoubiwa a=omid It's coming after #351 PR. I fixed the comments of the other PR here. fixes #260 Co-authored-by: vishalsodani <[email protected]> Co-authored-by: Omid Rad <[email protected]> Co-authored-by: Omid Rad <[email protected]>
It's been merged via the following PR: #480 |
Absolutely :) |
Pull Request
Related issue
Fixes #260
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!