Skip to content

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

Closed

Conversation

vishalsodani
Copy link
Contributor

Pull Request

Related issue

Fixes #260

What does this PR do?

  • ...

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@bidoubiwa bidoubiwa self-requested a review October 12, 2022 09:18
Copy link
Contributor

@bidoubiwa bidoubiwa left a 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

@bidoubiwa
Copy link
Contributor

I know it was not part of the PR description, but could you add (or update) the following code-samples based on this example:

  • get_typo_tolerance_1
  • update_typo_tolerance_1
  • reset_typo_tolerance_1
  • typo_tolerance_guide_1
  • typo_tolerance_guide_2
  • typo_tolerance_guide_3
  • typo_tolerance_guide_4
  • settings_guide_typo_tolerance_1
  • getting_started_typo_tolerance
  • update_settings_1

@vishalsodani
Copy link
Contributor Author

I know it was not part of the PR description, but could you add (or update) the following code-samples based on this example:

* get_typo_tolerance_1

* update_typo_tolerance_1

* reset_typo_tolerance_1

* typo_tolerance_guide_1

* typo_tolerance_guide_2

* typo_tolerance_guide_3

* typo_tolerance_guide_4

* settings_guide_typo_tolerance_1

* getting_started_typo_tolerance

* update_settings_1

ok. I will add these.

@vishalsodani vishalsodani force-pushed the typotolerance_customization branch from 60667db to 0674a1e Compare October 13, 2022 05:53
@vishalsodani
Copy link
Contributor Author

Hey @vishalsodani thanks for this contribution :)

Could you look at the specification? I think the parameters are optional

Can you please review? I have made the parameters optional. Is the implementation ok?

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

Very nice PR 🔥

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Oct 13, 2022

one_type and two_typos are u8 and not i64. See here

@bidoubiwa bidoubiwa added the enhancement New feature or request label Oct 13, 2022
@vishalsodani
Copy link
Contributor Author

Hi,

I feel there is an issue with this API design. If I tun this test, the test fails

`

     #[meilisearch_test]

     async fn test_set_typo_tolerance(client: Client, index: Index) {

    let typo_tolerance = TypoToleranceSettings {
        enabled: None,
        disable_on_attributes: Some(vec![]),
        disable_on_words: Some(vec![]),
        min_word_size_for_typos: Some(MinWordSizeForTypos {
            one_typo: Some(6),
            two_typos: Some(9),
        }),
    };
    let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
    client.wait_for_task(task_info, None, None).await.unwrap();

    let res = index.get_typo_tolerance().await.unwrap();

    assert_eq!(typo_tolerance, res);
}

    left: `TypoToleranceSettings { enabled: None, disable_on_attributes: Some([]), disable_on_words: Some([]), min_word_size_for_typos: Some(MinWordSizeForTypos { one_typo: Some(6), two_typos: Some(9) }) }`,

   right: `TypoToleranceSettings { enabled: Some(true), disable_on_attributes: Some([]), disable_on_words: Some([]), min_word_size_for_typos: Some(MinWordSizeForTypos { one_typo: Some(6), two_typos: Some(9) }) }`', src/settings.rs:1609:9

We are setting enabled as None which should not be allowed. Am I correct?

@vishalsodani
Copy link
Contributor Author

I know it was not part of the PR description, but could you add (or update) the following code-samples based on this example:

* get_typo_tolerance_1

* update_typo_tolerance_1

* reset_typo_tolerance_1

* typo_tolerance_guide_1

* typo_tolerance_guide_2

* typo_tolerance_guide_3

* typo_tolerance_guide_4

* settings_guide_typo_tolerance_1

* getting_started_typo_tolerance

* update_settings_1

Added.

@vishalsodani
Copy link
Contributor Author

Hey @vishalsodani thanks for this contribution :)

Could you look at the specification? I think the parameters are optional

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.

@vishalsodani
Copy link
Contributor Author

@bidoubiwa Hi, I am done with all the changes. Please review. Thanks!

Copy link
Contributor

@bidoubiwa bidoubiwa left a 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

@vishalsodani
Copy link
Contributor Author

  • default_one_typo_size

ok. Should I also revert the builder pattern? It does not seem that useful now.

@vishalsodani
Copy link
Contributor Author

Hey @vishalsodani

Actually, you are right and just raised a bug in Meilisearch haha! See this spec

Great!

@bidoubiwa
Copy link
Contributor

Should I also revert the builder pattern? It does not seem that useful now.

Yes probably it is best to keep consistency with the other nested settings like pagination that are not using the builder pattern.

@vishalsodani
Copy link
Contributor Author

@bidoubiwa

Can you remove:
Done

Copy link
Contributor

@bidoubiwa bidoubiwa left a 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![])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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]
Copy link
Contributor

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 and disabled_on_attributes still have the correct changes.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

`

Copy link
Contributor

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😅

Copy link
Contributor Author

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}")

Copy link
Contributor Author

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.

@bidoubiwa
Copy link
Contributor

This message is sent automatically

Thanks again for contributing to Meilisearch ❤️
If you are participating in Hacktoberfest, and you would like to receive some gift from Meilisearch too, please complete this form.

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Oct 26, 2022

Hey @vishalsodani
I'm a bit underwater right now. I gave you the hacktoberfest-accepted label in order to validate your PR for DO.

@omid
Copy link
Contributor

omid commented May 11, 2023

What's the state of this PR?
I can also help to improve it if there is something missing?

We need this.

Comment on lines +23 to +30
impl Default for MinWordSizeForTypos {
fn default() -> Self {
MinWordSizeForTypos {
one_typo: Some(5),
two_typos: Some(9),
}
}
}
Copy link
Member

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.

Suggested change
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,
}
}
}

Comment on lines +42 to +51
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()),
}
}
}
Copy link
Member

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.

Suggested change
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,
}
}
}

@omid
Copy link
Contributor

omid commented May 15, 2023

@irevoire, the original author hasn't had any activity on GitHub since then.
Seems like somebody else needs to take control.

meili-bors bot added a commit that referenced this pull request Jun 12, 2023
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]>
@omid
Copy link
Contributor

omid commented Jun 12, 2023

It's been merged via the following PR: #480
@bidoubiwa let's close this also 🙏🏼

@bidoubiwa
Copy link
Contributor

Absolutely :)

@bidoubiwa bidoubiwa closed this Jun 13, 2023
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.

Add support to the typo tolerance customization
5 participants