diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index c49b30e7..1446b216 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -710,7 +710,10 @@ typo_tolerance_guide_4: |- TwoTypos = 10 } }; - +typo_tolerance_guide_5: |- + var typoTolerance = new TypoTolerance { + DisableOnNumbers = true + }; await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance); get_all_tasks_paginating_1: |- ResourceResults taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 10 }); diff --git a/src/Meilisearch/TypoTolerance.cs b/src/Meilisearch/TypoTolerance.cs index f0624eaf..18cbad1d 100644 --- a/src/Meilisearch/TypoTolerance.cs +++ b/src/Meilisearch/TypoTolerance.cs @@ -32,6 +32,12 @@ public class TypoTolerance [JsonPropertyName("minWordSizeForTypos")] public TypoSize MinWordSizeForTypos { get; set; } + /// + /// Disable the typo tolerance feature for numbers. + /// + [JsonPropertyName("disableOnNumbers")] + public bool DisableOnNumbers { get; set; } + public class TypoSize { /// diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 395bc54a..16bfd75d 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -21,15 +21,7 @@ public SettingsTests(TFixture fixture) _defaultSettings = new Settings { - RankingRules = new string[] - { - "words", - "typo", - "proximity", - "attribute", - "sort", - "exactness", - }, + RankingRules = new string[] { "words", "typo", "proximity", "attribute", "sort", "exactness", }, DistinctAttribute = null, SearchableAttributes = new string[] { "*" }, DisplayedAttributes = new string[] { "*" }, @@ -46,30 +38,23 @@ public SettingsTests(TFixture fixture) Enabled = true, DisableOnAttributes = Array.Empty(), DisableOnWords = Array.Empty(), - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - OneTypo = 5, - TwoTypos = 9 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { OneTypo = 5, TwoTypos = 9 }, + DisableOnNumbers = false }, Faceting = new Faceting { MaxValuesPerFacet = 100, - SortFacetValuesBy = new Dictionary() - { - ["*"] = SortFacetValuesByType.Alpha - } + SortFacetValuesBy = + new Dictionary() { ["*"] = SortFacetValuesByType.Alpha } }, - Pagination = new Pagination - { - MaxTotalHits = 1000 - } + Pagination = new Pagination { MaxTotalHits = 1000 } }; } private delegate Task IndexGetMethod(CancellationToken cancellationToken = default); - private delegate Task IndexUpdateMethod(TValue newValue, CancellationToken cancellationToken = default); + private delegate Task IndexUpdateMethod(TValue newValue, + CancellationToken cancellationToken = default); private delegate Task IndexResetMethod(CancellationToken cancellationToken = default); @@ -99,8 +84,10 @@ public async Task UpdateSettings() SearchCutoffMs = 1000, }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings); - await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed - await AssertGetEquality(_index.GetSettingsAsync, SettingsWithDefaultedNullFields(newSettings, _defaultSettings)); + await AssertGetInequality(_index.GetSettingsAsync, + newSettings); // fields omitted in newSettings shouldn't have changed + await AssertGetEquality(_index.GetSettingsAsync, + SettingsWithDefaultedNullFields(newSettings, _defaultSettings)); } [Fact] @@ -113,26 +100,24 @@ public async Task TwoStepUpdateSettings() DistinctAttribute = "name", Synonyms = new Dictionary> { - { "hp", new string[] { "harry potter" } }, - { "harry potter", new string[] { "hp" } }, + { "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } }, }, Dictionary = new string[] { "dictionary" } }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettingsOne); var expectedSettingsOne = SettingsWithDefaultedNullFields(newSettingsOne, _defaultSettings); - await AssertGetInequality(_index.GetSettingsAsync, newSettingsOne); // fields omitted in newSettingsOne shouldn't have changed + await AssertGetInequality(_index.GetSettingsAsync, + newSettingsOne); // fields omitted in newSettingsOne shouldn't have changed await AssertGetEquality(_index.GetSettingsAsync, expectedSettingsOne); // Second update: this one should not overwritten StopWords and DistinctAttribute. - var newSettingsTwo = new Settings - { - SearchableAttributes = new string[] { "name" }, - }; + var newSettingsTwo = new Settings { SearchableAttributes = new string[] { "name" }, }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettingsTwo); var expectedSettingsTwo = SettingsWithDefaultedNullFields(newSettingsTwo, expectedSettingsOne); - await AssertGetInequality(_index.GetSettingsAsync, newSettingsTwo); // fields omitted in newSettingsTwo shouldn't have changed + await AssertGetInequality(_index.GetSettingsAsync, + newSettingsTwo); // fields omitted in newSettingsTwo shouldn't have changed await AssertGetEquality(_index.GetSettingsAsync, expectedSettingsTwo); } @@ -150,8 +135,10 @@ public async Task ResetSettings() Dictionary = new string[] { "dictionary" } }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings); - await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed - await AssertGetEquality(_index.GetSettingsAsync, SettingsWithDefaultedNullFields(newSettings, _defaultSettings)); + await AssertGetInequality(_index.GetSettingsAsync, + newSettings); // fields omitted in newSettings shouldn't have changed + await AssertGetEquality(_index.GetSettingsAsync, + SettingsWithDefaultedNullFields(newSettings, _defaultSettings)); await AssertResetSuccess(_index.ResetSettingsAsync); await AssertGetEquality(_index.GetSettingsAsync, _defaultSettings); @@ -393,8 +380,7 @@ public async Task UpdateSynonyms() { var newSynonyms = new Dictionary> { - { "hp", new string[] { "harry potter" } }, - { "harry potter", new string[] { "hp" } }, + { "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } }, }; await AssertUpdateSuccess(_index.UpdateSynonymsAsync, newSynonyms); await AssertGetEquality(_index.GetSynonymsAsync, newSynonyms); @@ -405,8 +391,7 @@ public async Task ResetSynonyms() { var newSynonyms = new Dictionary> { - { "hp", new string[] { "harry potter" } }, - { "harry potter", new string[] { "hp" } }, + { "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } }, }; await AssertUpdateSuccess(_index.UpdateSynonymsAsync, newSynonyms); await AssertGetEquality(_index.GetSynonymsAsync, newSynonyms); @@ -427,10 +412,7 @@ public async Task UpdateTypoTolerance() var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 } }; var returnedTypoTolerance = new TypoTolerance @@ -438,40 +420,50 @@ public async Task UpdateTypoTolerance() Enabled = true, DisableOnAttributes = Array.Empty(), DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12, - OneTypo = 5 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 } }; await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance); await AssertGetEquality(_index.GetTypoToleranceAsync, returnedTypoTolerance); } + [Fact] - public async Task UpdateTypoTolerancePartially() + public async Task UpdateTypoToleranceForDisableOnNumbers() { var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 }, + DisableOnNumbers = true }; - var otherUpdateTypoTolerance = new TypoTolerance + var returnedTypoTolerance = new TypoTolerance { - DisableOnAttributes = new string[] { "title" }, + Enabled = true, + DisableOnAttributes = new string[] { }, + DisableOnWords = new string[] { "harry", "potter" }, + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 }, + DisableOnNumbers = true }; + await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance); + await AssertGetEquality(_index.GetTypoToleranceAsync, returnedTypoTolerance); + } + + [Fact] + public async Task UpdateTypoTolerancePartially() + { + var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, }; + + var otherUpdateTypoTolerance = new TypoTolerance { DisableOnAttributes = new string[] { "title" }, }; + var returnedTypoTolerance = new TypoTolerance { Enabled = true, DisableOnAttributes = new string[] { "title" }, DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 9, - OneTypo = 5 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 9, OneTypo = 5 } }; await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance); @@ -485,10 +477,7 @@ public async Task ResetTypoTolerance() var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 } }; var returnedTypoTolerance = new TypoTolerance @@ -496,11 +485,7 @@ public async Task ResetTypoTolerance() Enabled = true, DisableOnAttributes = Array.Empty(), DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12, - OneTypo = 5 - } + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 } }; await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance); @@ -510,6 +495,7 @@ public async Task ResetTypoTolerance() await AssertGetEquality(_index.GetTypoToleranceAsync, _defaultSettings.TypoTolerance); } + [Fact] public async Task GetFaceting() { @@ -560,10 +546,7 @@ public async Task GetPagination() [Fact] public async Task UpdatePagination() { - var newPagination = new Pagination - { - MaxTotalHits = 20 - }; + var newPagination = new Pagination { MaxTotalHits = 20 }; await AssertUpdateSuccess(_index.UpdatePaginationAsync, newPagination); await AssertGetEquality(_index.GetPaginationAsync, newPagination); @@ -572,10 +555,7 @@ public async Task UpdatePagination() [Fact] public async Task ResetPagination() { - var newPagination = new Pagination - { - MaxTotalHits = 30 - }; + var newPagination = new Pagination { MaxTotalHits = 30 }; await AssertUpdateSuccess(_index.UpdatePaginationAsync, newPagination); await AssertGetEquality(_index.GetPaginationAsync, newPagination);