From d38a01c002571f88b61da9328e7cb7c2b0431591 Mon Sep 17 00:00:00 2001 From: TebbeM Date: Mon, 15 Sep 2025 09:35:15 +0200 Subject: [PATCH 1/3] add disableOnNumbers to TypoTolerance.cs settings and added additional test --- .env | 2 +- src/Meilisearch/TypoTolerance.cs | 6 +++++ tests/Meilisearch.Tests/SettingsTests.cs | 32 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 767307bf..23c6088d 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -MEILISEARCH_VERSION=v1.9.0 +MEILISEARCH_VERSION=v1.15.0 PROXIED_MEILISEARCH=http://nginx/api/ MEILISEARCH_URL=http://meilisearch:7700 diff --git a/src/Meilisearch/TypoTolerance.cs b/src/Meilisearch/TypoTolerance.cs index f0624eaf..b0e00cc4 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 14eb66d4..39aaa266 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -441,6 +441,37 @@ public async Task UpdateTypoTolerance() await AssertGetEquality(_index.GetTypoToleranceAsync, returnedTypoTolerance); } + + [Fact] + public async Task UpdateTypoToleranceForDisableOnNumbers() + { + var newTypoTolerance = new TypoTolerance + { + DisableOnWords = new string[] { "harry", "potter" }, + MinWordSizeForTypos = new TypoTolerance.TypoSize + { + TwoTypos = 12 + }, + DisableOnNumbers = true + }; + + var returnedTypoTolerance = new TypoTolerance + { + 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() { @@ -502,6 +533,7 @@ public async Task ResetTypoTolerance() await AssertGetEquality(_index.GetTypoToleranceAsync, _defaultSettings.TypoTolerance); } + [Fact] public async Task GetFaceting() { From e20c2bc0d3df3900105ec7926265a3cbd94e6f8b Mon Sep 17 00:00:00 2001 From: TebbeM Date: Mon, 15 Sep 2025 09:50:50 +0200 Subject: [PATCH 2/3] add TypoTolerance with DisableOnNumbers to code-samples.meilisearch.yaml --- .code-samples.meilisearch.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 }); From a2c96910e37eb32c32963eba4fe52338c964a01f Mon Sep 17 00:00:00 2001 From: TebbeM Date: Mon, 15 Sep 2025 10:18:47 +0200 Subject: [PATCH 3/3] fixed the integration tests to account for DisableOnNumbers beeing always set --- src/Meilisearch/TypoTolerance.cs | 2 +- tests/Meilisearch.Tests/SettingsTests.cs | 122 +++++++---------------- 2 files changed, 36 insertions(+), 88 deletions(-) diff --git a/src/Meilisearch/TypoTolerance.cs b/src/Meilisearch/TypoTolerance.cs index b0e00cc4..18cbad1d 100644 --- a/src/Meilisearch/TypoTolerance.cs +++ b/src/Meilisearch/TypoTolerance.cs @@ -36,7 +36,7 @@ public class TypoTolerance /// Disable the typo tolerance feature for numbers. /// [JsonPropertyName("disableOnNumbers")] - public bool? DisableOnNumbers { get; set; } + public bool DisableOnNumbers { get; set; } public class TypoSize { diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 439e19e5..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,11 +420,7 @@ 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); @@ -456,10 +434,7 @@ public async Task UpdateTypoToleranceForDisableOnNumbers() var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12 - }, + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 }, DisableOnNumbers = true }; @@ -468,11 +443,7 @@ public async Task UpdateTypoToleranceForDisableOnNumbers() Enabled = true, DisableOnAttributes = new string[] { }, DisableOnWords = new string[] { "harry", "potter" }, - MinWordSizeForTypos = new TypoTolerance.TypoSize - { - TwoTypos = 12, - OneTypo = 5 - }, + MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 }, DisableOnNumbers = true }; @@ -483,26 +454,16 @@ public async Task UpdateTypoToleranceForDisableOnNumbers() [Fact] public async Task UpdateTypoTolerancePartially() { - var newTypoTolerance = new TypoTolerance - { - DisableOnWords = new string[] { "harry", "potter" }, - }; + var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, }; - var otherUpdateTypoTolerance = new TypoTolerance - { - DisableOnAttributes = new string[] { "title" }, - }; + 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); @@ -516,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 @@ -527,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); @@ -592,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); @@ -604,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);