From 518e15b7c123db5aa1aec78a21887cf249228451 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:19:31 -0600 Subject: [PATCH 01/11] get, update, reset dictionary functions --- src/Meilisearch/Index.Dictionary.cs | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Meilisearch/Index.Dictionary.cs diff --git a/src/Meilisearch/Index.Dictionary.cs b/src/Meilisearch/Index.Dictionary.cs new file mode 100644 index 00000000..f5c649f8 --- /dev/null +++ b/src/Meilisearch/Index.Dictionary.cs @@ -0,0 +1,45 @@ +using System.Net.Http.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Meilisearch +{ + public partial class Index + { + /// + /// Gets all the settings of an index. + /// + /// The cancellation token for this call. + /// Returns all the settings. + public async Task GetDictionaryAsync(CancellationToken cancellationToken = default) + { + return await _http.GetFromJsonAsync($"indexes/{Uid}/settings/dictionary", cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + + /// + /// Gets all the settings of an index. + /// + /// Dictionary object. + /// The cancellation token for this call. + /// Returns all the settings. + public async Task UpdateDictionaryAsync(string[] dictionary, CancellationToken cancellationToken = default) + { + var responseMessage = + await _http.PutAsJsonAsync($"indexes/{Uid}/settings/dictionary", dictionary, cancellationToken: cancellationToken) + .ConfigureAwait(false); + return await responseMessage.Content.ReadFromJsonAsync(cancellationToken: cancellationToken).ConfigureAwait(false); + } + + /// + /// Resets all the settings to their default values. + /// + /// The cancellation token for this call. + /// Returns the task info of the asynchronous task. + public async Task ResetDictionaryAsync(CancellationToken cancellationToken = default) + { + var httpResponse = await _http.DeleteAsync($"indexes/{Uid}/settings/dictionary", cancellationToken).ConfigureAwait(false); + return await httpResponse.Content.ReadFromJsonAsync(cancellationToken: cancellationToken).ConfigureAwait(false); + } + } +} From e255aac94a802e26ba03f952f80e2f55c9113ece Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:19:45 -0600 Subject: [PATCH 02/11] dictionary property added to Settings --- src/Meilisearch/Settings.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Meilisearch/Settings.cs b/src/Meilisearch/Settings.cs index b31f9f27..bb65e1bf 100644 --- a/src/Meilisearch/Settings.cs +++ b/src/Meilisearch/Settings.cs @@ -86,6 +86,12 @@ public class Settings [JsonPropertyName("pagination")] public Pagination Pagination { get; set; } + /// + /// Gets or sets the dictionary object. + /// + [JsonPropertyName("dictionary")] + public string[] Dictionary { get; set; } + /// /// Gets or sets the proximity precision attribute. /// From 4b1dec07f9147d5758ccbb207e9c4eab5b090f91 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:20:25 -0600 Subject: [PATCH 03/11] Index.Dictionary.cs depends on Index.cs - is this necessary? --- src/Meilisearch/Meilisearch.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Meilisearch/Meilisearch.csproj b/src/Meilisearch/Meilisearch.csproj index b1fc09c2..30fe7a26 100644 --- a/src/Meilisearch/Meilisearch.csproj +++ b/src/Meilisearch/Meilisearch.csproj @@ -39,6 +39,9 @@ Index.cs + + Index.cs + Index.cs From 7e01e726fdbd31294f4af9ad2d2f8743b51a61de Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:20:49 -0600 Subject: [PATCH 04/11] rm unnecessary whitespace --- tests/Meilisearch.Tests/SettingsTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 14eb66d4..6dba13ed 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -591,8 +591,7 @@ public async Task ResetProximityPrecision() await AssertUpdateSuccess(_index.UpdateProximityPrecisionAsync, newPrecision); await AssertGetEquality(_index.GetProximityPrecisionAsync, newPrecision); - await AssertResetSuccess(_index.ResetProximityPrecisionAsync - ); + await AssertResetSuccess(_index.ResetProximityPrecisionAsync); await AssertGetEquality(_index.GetProximityPrecisionAsync, _defaultSettings.ProximityPrecision); } From d3f11d1988919b29947254f3edf43ba95ed5e523 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:21:29 -0600 Subject: [PATCH 05/11] get, update, reset dictionary tests. --- tests/Meilisearch.Tests/SettingsTests.cs | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 6dba13ed..98f0986d 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -34,6 +34,7 @@ public SettingsTests(TFixture fixture) DistinctAttribute = null, SearchableAttributes = new string[] { "*" }, DisplayedAttributes = new string[] { "*" }, + Dictionary = new string[] { }, StopWords = new string[] { }, SeparatorTokens = new List { }, NonSeparatorTokens = new List { }, @@ -595,6 +596,33 @@ public async Task ResetProximityPrecision() await AssertGetEquality(_index.GetProximityPrecisionAsync, _defaultSettings.ProximityPrecision); } + [Fact] + public async Task GetDictionaryAsync() + { + await AssertGetEquality(_index.GetDictionaryAsync, _defaultSettings.Dictionary); + } + + [Fact] + public async Task UpdateDictionaryAsync() + { + var newDictionary = new string[] { "W. E. B.", "W.E.B." }; + + await AssertUpdateSuccess(_index.UpdateDictionaryAsync, newDictionary); + await AssertGetEquality(_index.GetDictionaryAsync, newDictionary); + } + + [Fact] + public async Task ResetDictionaryAsync() + { + var newDictionary = new string[] { "W. E. B.", "W.E.B." }; + + await AssertUpdateSuccess(_index.UpdateDictionaryAsync, newDictionary); + await AssertGetEquality(_index.GetDictionaryAsync, newDictionary); + + await AssertResetSuccess(_index.ResetDictionaryAsync); + await AssertGetEquality(_index.GetDictionaryAsync, _defaultSettings.Dictionary); + } + private static Settings SettingsWithDefaultedNullFields(Settings inputSettings, Settings defaultSettings) { return new Settings From 93c4b16a05baa4f53f71d90c40968b9e06b159bd Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 10:21:56 -0600 Subject: [PATCH 06/11] get, update, reset code samples --- .code-samples.meilisearch.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 0a788658..8614befa 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -782,3 +782,10 @@ distinct_attribute_guide_distinct_parameter_1: |- Distinct = "sku" }; await client.Index("products").SearchAsync("white shirt", params); +get_dictionary_1: |- + var indexDictionary = await client.Index("products").GetDictionaryAsync(); +update_dictionary_1: |- + var newDictionary = new string[] { "W. E. B.", "W.E.B." }; + await client.Index("products").UpdateDictionaryAsync(newDictionary); +reset_dictionary_1: |- + await client.Index("products").ResetDictionaryAsync(); From ffe671bd20ac133cde77612aa33f09edbedda036 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 13:48:59 -0600 Subject: [PATCH 07/11] c# code sample more accurately reflects curl example --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 8614befa..cb3642eb 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -785,7 +785,7 @@ distinct_attribute_guide_distinct_parameter_1: |- get_dictionary_1: |- var indexDictionary = await client.Index("products").GetDictionaryAsync(); update_dictionary_1: |- - var newDictionary = new string[] { "W. E. B.", "W.E.B." }; + var newDictionary = new string[] { "J. R. R.", "W. E. B." }; await client.Index("products").UpdateDictionaryAsync(newDictionary); reset_dictionary_1: |- await client.Index("products").ResetDictionaryAsync(); From d3efc21b082def1564f2811630c9da14637dac3c Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 13 Nov 2024 15:17:06 -0600 Subject: [PATCH 08/11] corrected the summary docs. --- src/Meilisearch/Index.Dictionary.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Meilisearch/Index.Dictionary.cs b/src/Meilisearch/Index.Dictionary.cs index f5c649f8..3f9ee7fb 100644 --- a/src/Meilisearch/Index.Dictionary.cs +++ b/src/Meilisearch/Index.Dictionary.cs @@ -7,10 +7,10 @@ namespace Meilisearch public partial class Index { /// - /// Gets all the settings of an index. + /// Gets the dictionary of an index. /// /// The cancellation token for this call. - /// Returns all the settings. + /// Returns the dictionary. public async Task GetDictionaryAsync(CancellationToken cancellationToken = default) { return await _http.GetFromJsonAsync($"indexes/{Uid}/settings/dictionary", cancellationToken: cancellationToken) @@ -18,11 +18,11 @@ public async Task GetDictionaryAsync(CancellationToken cancellationTok } /// - /// Gets all the settings of an index. + /// Updates the dictionary of an index. /// /// Dictionary object. /// The cancellation token for this call. - /// Returns all the settings. + /// Returns the task info of the asynchronous task. public async Task UpdateDictionaryAsync(string[] dictionary, CancellationToken cancellationToken = default) { var responseMessage = @@ -32,7 +32,7 @@ await _http.PutAsJsonAsync($"indexes/{Uid}/settings/dictionary", dictionary, can } /// - /// Resets all the settings to their default values. + /// Resets the dictionary to their default values. /// /// The cancellation token for this call. /// Returns the task info of the asynchronous task. From 59ddfeb033f9bdfe92c41ab58c2c687726a4a5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine?= Date: Wed, 27 Nov 2024 11:10:38 +0100 Subject: [PATCH 09/11] Apply suggestions from code review --- .code-samples.meilisearch.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index cb3642eb..90f95082 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -783,9 +783,9 @@ distinct_attribute_guide_distinct_parameter_1: |- }; await client.Index("products").SearchAsync("white shirt", params); get_dictionary_1: |- - var indexDictionary = await client.Index("products").GetDictionaryAsync(); + var indexDictionary = await client.Index("books").GetDictionaryAsync(); update_dictionary_1: |- var newDictionary = new string[] { "J. R. R.", "W. E. B." }; - await client.Index("products").UpdateDictionaryAsync(newDictionary); + await client.Index("books").UpdateDictionaryAsync(newDictionary); reset_dictionary_1: |- - await client.Index("products").ResetDictionaryAsync(); + await client.Index("books").ResetDictionaryAsync(); From 1c4f1925cbf6062bff3c3a9617353de9191c16fc Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 27 Nov 2024 09:49:19 -0600 Subject: [PATCH 10/11] implement dictionary as IEnumerable for more flexibility and to match similar settings properties --- src/Meilisearch/Index.Dictionary.cs | 5 +++-- src/Meilisearch/Settings.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Meilisearch/Index.Dictionary.cs b/src/Meilisearch/Index.Dictionary.cs index 3f9ee7fb..f74f6bcb 100644 --- a/src/Meilisearch/Index.Dictionary.cs +++ b/src/Meilisearch/Index.Dictionary.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Net.Http.Json; using System.Threading; using System.Threading.Tasks; @@ -11,7 +12,7 @@ public partial class Index /// /// The cancellation token for this call. /// Returns the dictionary. - public async Task GetDictionaryAsync(CancellationToken cancellationToken = default) + public async Task> GetDictionaryAsync(CancellationToken cancellationToken = default) { return await _http.GetFromJsonAsync($"indexes/{Uid}/settings/dictionary", cancellationToken: cancellationToken) .ConfigureAwait(false); @@ -23,7 +24,7 @@ public async Task GetDictionaryAsync(CancellationToken cancellationTok /// Dictionary object. /// The cancellation token for this call. /// Returns the task info of the asynchronous task. - public async Task UpdateDictionaryAsync(string[] dictionary, CancellationToken cancellationToken = default) + public async Task UpdateDictionaryAsync(IEnumerable dictionary, CancellationToken cancellationToken = default) { var responseMessage = await _http.PutAsJsonAsync($"indexes/{Uid}/settings/dictionary", dictionary, cancellationToken: cancellationToken) diff --git a/src/Meilisearch/Settings.cs b/src/Meilisearch/Settings.cs index bb65e1bf..236ed77e 100644 --- a/src/Meilisearch/Settings.cs +++ b/src/Meilisearch/Settings.cs @@ -90,7 +90,7 @@ public class Settings /// Gets or sets the dictionary object. /// [JsonPropertyName("dictionary")] - public string[] Dictionary { get; set; } + public IEnumerable Dictionary { get; set; } /// /// Gets or sets the proximity precision attribute. From 2890f4a021f0c2485d3fb7a01f36bfc7406af030 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 27 Nov 2024 09:49:26 -0600 Subject: [PATCH 11/11] fix for tests. implement Dictionary in SettingsWithDefaultedNullFields. --- tests/Meilisearch.Tests/SettingsTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 98f0986d..08c60177 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -92,6 +92,7 @@ public async Task UpdateSettings() SearchableAttributes = new string[] { "name", "genre" }, StopWords = new string[] { "of", "the" }, DistinctAttribute = "name", + Dictionary = new string[] { "dictionary" } }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings); await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed @@ -111,6 +112,7 @@ public async Task TwoStepUpdateSettings() { "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } }, }, + Dictionary = new string[] { "dictionary" } }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettingsOne); @@ -140,7 +142,8 @@ public async Task ResetSettings() DistinctAttribute = "name", DisplayedAttributes = new string[] { "name" }, RankingRules = new string[] { "typo" }, - FilterableAttributes = new string[] { "genre" } + FilterableAttributes = new string[] { "genre" }, + Dictionary = new string[] { "dictionary" } }; await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings); await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed @@ -640,7 +643,8 @@ private static Settings SettingsWithDefaultedNullFields(Settings inputSettings, TypoTolerance = inputSettings.TypoTolerance ?? defaultSettings.TypoTolerance, Faceting = inputSettings.Faceting ?? defaultSettings.Faceting, Pagination = inputSettings.Pagination ?? defaultSettings.Pagination, - ProximityPrecision = inputSettings.ProximityPrecision ?? defaultSettings.ProximityPrecision + ProximityPrecision = inputSettings.ProximityPrecision ?? defaultSettings.ProximityPrecision, + Dictionary = inputSettings.Dictionary ?? defaultSettings.Dictionary, }; }