-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
583: Add dictionary support r=curquiza a=danFbach # Pull Request ## Related issue Fixes #483 ## What does this PR do? - Adds dictionary support - tests added and passing - code samples added ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Dan Fehrenbach <[email protected]> Co-authored-by: Clémentine <[email protected]>
- Loading branch information
Showing
5 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Gets the dictionary of an index. | ||
/// </summary> | ||
/// <param name="cancellationToken">The cancellation token for this call.</param> | ||
/// <returns>Returns the dictionary.</returns> | ||
public async Task<IEnumerable<string>> GetDictionaryAsync(CancellationToken cancellationToken = default) | ||
{ | ||
return await _http.GetFromJsonAsync<string[]>($"indexes/{Uid}/settings/dictionary", cancellationToken: cancellationToken) | ||
.ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Updates the dictionary of an index. | ||
/// </summary> | ||
/// <param name="dictionary">Dictionary object.</param> | ||
/// <param name="cancellationToken">The cancellation token for this call.</param> | ||
/// <returns>Returns the task info of the asynchronous task.</returns> | ||
public async Task<TaskInfo> UpdateDictionaryAsync(IEnumerable<string> dictionary, CancellationToken cancellationToken = default) | ||
{ | ||
var responseMessage = | ||
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/dictionary", dictionary, cancellationToken: cancellationToken) | ||
.ConfigureAwait(false); | ||
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Resets the dictionary to their default values. | ||
/// </summary> | ||
/// <param name="cancellationToken">The cancellation token for this call.</param> | ||
/// <returns>Returns the task info of the asynchronous task.</returns> | ||
public async Task<TaskInfo> ResetDictionaryAsync(CancellationToken cancellationToken = default) | ||
{ | ||
var httpResponse = await _http.DeleteAsync($"indexes/{Uid}/settings/dictionary", cancellationToken).ConfigureAwait(false); | ||
return await httpResponse.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters