diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 55f2dc2a..19471adc 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -788,3 +788,10 @@ search_parameter_reference_ranking_score_threshold_1: |- RankingScoreThreshold = 0.2M }; await client.Index("INDEX_NAME").SearchAsync("badman", params); +get_dictionary_1: |- + var indexDictionary = await client.Index("books").GetDictionaryAsync(); +update_dictionary_1: |- + var newDictionary = new string[] { "J. R. R.", "W. E. B." }; + await client.Index("books").UpdateDictionaryAsync(newDictionary); +reset_dictionary_1: |- + await client.Index("books").ResetDictionaryAsync(); diff --git a/src/Meilisearch/Index.Dictionary.cs b/src/Meilisearch/Index.Dictionary.cs new file mode 100644 index 00000000..f74f6bcb --- /dev/null +++ b/src/Meilisearch/Index.Dictionary.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Net.Http.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Meilisearch +{ + public partial class Index + { + /// + /// Gets the dictionary of an index. + /// + /// The cancellation token for this call. + /// Returns the dictionary. + public async Task> GetDictionaryAsync(CancellationToken cancellationToken = default) + { + return await _http.GetFromJsonAsync($"indexes/{Uid}/settings/dictionary", cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + + /// + /// Updates the dictionary of an index. + /// + /// Dictionary object. + /// The cancellation token for this call. + /// Returns the task info of the asynchronous task. + public async Task UpdateDictionaryAsync(IEnumerable 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 the dictionary 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); + } + } +} diff --git a/src/Meilisearch/Meilisearch.csproj b/src/Meilisearch/Meilisearch.csproj index ca8b0426..5e0555b2 100644 --- a/src/Meilisearch/Meilisearch.csproj +++ b/src/Meilisearch/Meilisearch.csproj @@ -39,6 +39,9 @@ Index.cs + + Index.cs + Index.cs diff --git a/src/Meilisearch/Settings.cs b/src/Meilisearch/Settings.cs index b31f9f27..236ed77e 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 IEnumerable Dictionary { get; set; } + /// /// Gets or sets the proximity precision attribute. /// diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 14eb66d4..08c60177 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 { }, @@ -91,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 @@ -110,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); @@ -139,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 @@ -591,11 +595,37 @@ 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); } + [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 @@ -613,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, }; }