Skip to content

Commit

Permalink
Merge #281
Browse files Browse the repository at this point in the history
281: Changes related to the next Meilisearch release (v0.28.0) r=brunoocasali a=meili-bot

Related to this issue: meilisearch/integration-guides#205

This PR:
- gathers the changes related to the next Meilisearch release (v0.28.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.28.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.28.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._

Done:
- #282 
- #286 
- #287
- #288
- #289 
- #290 
- #291 
- #292 
- #293 
- #298

Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Clémentine Urquizar <clementine@meilisearch.com>
Co-authored-by: Amélie <alallema@users.noreply.github.com>
Co-authored-by: alallema <amelie@meilisearch.com>
  • Loading branch information
5 people authored Jul 28, 2022
2 parents b60c22d + d50b774 commit cc6eddd
Show file tree
Hide file tree
Showing 41 changed files with 853 additions and 343 deletions.
88 changes: 72 additions & 16 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,62 @@
---
get_one_index_1: |-
list_all_indexes_1: |-
await client.GetAllIndexesAsync(new IndexesQuery { Limit = 3 });
create_an_index_1: |-
TaskInfo task = await client.CreateIndexAsync("movies", "id");
update_an_index_1: |-
TaskInfo task = await client.UpdateIndexAsync("movies", "id");
delete_an_index_1: |-
get_one_document_1: |-
await client.Index("movies").GetDocumentAsync<Movie>(25684, new List<string> { "id", "title", "poster", "release_date" });
get_documents_1: |-
add_or_replace_documents_1: |-
add_or_update_documents_1: |-
delete_all_documents_1: |-
delete_one_document_1: |-
delete_documents_1: |-
search_post_1: |-
get_task_by_index_1: |-
TaskInfo task = await client.Index("movies").GetTaskAsync(1);
get_all_tasks_by_index_1: |-
Result taskResult = await client.Index("movies").GetTasksAsync();
var tasks = taskResult.Result;
get_task_1: |
TaskInfo task = await client.GetTaskAsync(1);
get_all_tasks_1: |
Result taskResult = await client.GetTasksAsync();
var tasks = taskResult.Result;
ResourceResults<Task> taskResult = await client.GetTasksAsync();
get_settings_1: |-
update_settings_1: |-
Settings newSettings = new Settings
{
RankingRules = new string[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:desc",
"rank:desc"
},
DistinctAttribute = "movie_id",
SearchableAttributes = new string[] { "title", "overview", "genres" },
DisplayedAttributes = new string[] { "title", "overview", "genres", "release_date" },
SortableAttributes = new string[] { "title", "release_date" },
StopWords = new string[] { "the", "a", "an" },
Synonyms = new Dictionary<string, IEnumerable<string>>
{
{ "wolverine", new string[] { "xmen", "logan" } },
{ "logan", new string[] { "wolverine" } },
},
FilterableAttributes = new string[] { },
TypoTolerance = new TypoTolerance
{
DisableOnAttributes = new string[] { "title" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
OneTypo = 8,
TwoTypos = 10
}
}
};
TaskInfo task = await client.Index("movies").UpdateSettingsAsync(newFilters);
reset_settings_1: |-
get_synonyms_1: |-
update_synonyms_1: |-
Expand Down Expand Up @@ -83,6 +114,12 @@ search_parameter_guide_retrieve_1: |-
search_parameter_guide_crop_1: |-
search_parameter_guide_highlight_1: |-
search_parameter_guide_matches_1: |-
await client.Index("movies").SearchAsync<T>(
"winter feast",
new SearchQuery
{
ShowMatchesPosition = True,
});
settings_guide_synonyms_1: |-
settings_guide_stop_words_1: |-
settings_guide_ranking_rules_1: |-
Expand Down Expand Up @@ -140,7 +177,7 @@ getting_started_add_documents_md: |-
```
[About this SDK](https://www.github.com/meilisearch/meilisearch-dotnet)
getting_started_check_task_status: |-
TaskInfo task = await client.Index("movies").GetTaskAsync(1);
TaskInfo task = await client.GetTaskAsync(0);
getting_started_search_md: |-
```csharp
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
Expand Down Expand Up @@ -235,10 +272,10 @@ faceted_search_filter_1: |-
};
SearchResult<Movie> movies = await client.Index("movies").SearchAsync<Movie>("thriller", filters);
faceted_search_facets_distribution_1: |-
faceted_search_facets_1: |-
SearchQuery filters = new SearchQuery()
{
FacetsDistribution = new string[] { "genres" }
Facets = new string[] { "genres" }
};
SearchResult<Movie> movies = await client.Index("movies").SearchAsync<Movie>("Batman", filters);
Expand All @@ -258,7 +295,6 @@ landing_getting_started_1: |-
var task = await client.Index("movies").AddDocumentsAsync<Movie>(documents);
post_dump_1: |-
get_dump_status_1: |-
phrase_search_1: |-
sorting_guide_update_sortable_attributes_1: |-
sorting_guide_update_ranking_rules_1: |-
Expand Down Expand Up @@ -323,8 +359,7 @@ authorization_header_1: |-
get_one_key_1: |-
Key key = await client.GetKeyAsync("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4");
get_all_keys_1: |-
Result keyResult = await client.GetKeysAsync();
var keys = keyResult.Result;
ResourceResults<Key> keyResult = await client.GetKeysAsync(new KeysQuery { Limit = 3 });
create_a_key_1: |-
Key keyOptions = new Key
{
Expand All @@ -337,7 +372,7 @@ create_a_key_1: |-
update_a_key_1: |-
// Not implemented yet
delete_a_key_1: |-
client.DeleteKeyAsync("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
client.DeleteKeyAsync("6062abda-a5aa-4414-ac91-ecd7944c0f8d")
security_guide_search_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://127.0.0.1:7700", "apiKey");
SearchResult<Patient> searchResult = await client.Index("patient_medical_records").SearchAsync<Patient>();
Expand All @@ -355,11 +390,11 @@ security_guide_create_key_1: |-
Key createdKey = await this.client.CreateKeyAsync(keyOptions);
security_guide_list_keys_1: |-
MeilisearchClient client = new MeilisearchClient("http://127.0.0.1:7700", "masterKey");
Result keyResult = await client.GetKeysAsync();
ResourceResults<Key> keyResult = await client.GetKeysAsync();
var keys = keyResult.Result;
security_guide_delete_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://127.0.0.1:7700", "masterKey");
client.DeleteKeyAsync("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
client.DeleteKeyAsync("ac5cd97d-5a4b-4226-a868-2d0eb6d197ab")
tenant_token_guide_generate_sdk_1: |-
var apiKey = "B5KdX2MY2jV6EXfUs6scSfmC...";
var expiresAt = new DateTime(2025, 12, 20);
Expand Down Expand Up @@ -425,3 +460,24 @@ settings_guide_typo_tolerance_1: |-
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
get_all_tasks_filtering_1: |-
ResourceResults<TaskInfo> taskResult = await client.Index("movies").GetTasksAsync();
// OR
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { IndexUid = "movies" });
get_all_tasks_filtering_2: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery {
Status = new List<string>() { "succeeded", "failed" },
Types = new List<string>() { "documentAdditionOrUpdate" },
});
get_all_tasks_paginating_1: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 10 });
get_all_tasks_paginating_2: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 8 });
get_pagination_settings_1: |-
update_pagination_settings_1: |-
reset_pagination_settings_1: |-
get_faceting_settings_1: |-
update_faceting_settings_1: |-
reset_faceting_settings_1: |-
settings_guide_faceting_1: |-
settings_guide_pagination_1: |-
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ JSON Output:

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).

## 🎬 Examples

Expand Down Expand Up @@ -231,7 +231,7 @@ The returned `task` is a `TaskInfo` that can access to `Uid` to get the status o
#### Get Documents <!-- omit in toc -->

```c#
var documents = await index.GetDocumentsAsync<Movie>(new DocumentQuery { Limit = 1 });
var documents = await index.GetDocumentsAsync<Movie>(new DocumentsQuery { Limit = 1 });
```

#### Get Document by Id <!-- omit in toc -->
Expand Down
28 changes: 0 additions & 28 deletions src/Meilisearch/DumpStatus.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/Meilisearch/Errors/MeilisearchTenantTokenApiKeyUidInvalid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Meilisearch
{
/// <summary>
/// Represents an exception thrown when `apiKey` is not present
/// to sign correctly the Tenant Token generation.
/// </summary>
public class MeilisearchTenantTokenApiKeyUidInvalid : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="MeilisearchTenantTokenApiKeyUidInvalid"/> class.
/// </summary>
public MeilisearchTenantTokenApiKeyUidInvalid()
: base("Cannot generate a signed token without a valid apiKeyUid. Provide one in the method params.")
{
}
}
}
22 changes: 22 additions & 0 deletions src/Meilisearch/Extensions/HttpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -89,5 +91,25 @@ private static StringContent PrepareJsonPayload<T>(T body, JsonSerializerOptions

return payload;
}

private static Task<HttpResponseMessage> PatchAsync(this HttpClient client, string requestUri, HttpContent content, CancellationToken cancellationToken)
{
var uri = new Uri(requestUri, UriKind.RelativeOrAbsolute);
return client.PatchAsync(uri, content, cancellationToken);
}

private static Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent content, CancellationToken cancellationToken)
{
// HttpClient.PatchAsync is not available in .NET standard and NET462
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, requestUri) { Content = content };
return client.SendAsync(request, cancellationToken);
}

internal static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string requestUri, TValue value, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)
{
var content = JsonContent.Create(value, mediaType: null, options);
return client.PatchAsync(requestUri, content, cancellationToken);
}
}
}
25 changes: 18 additions & 7 deletions src/Meilisearch/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,30 @@ internal static IDictionary<string, string> AsDictionary(this object source, Bin
}

/// <summary>
/// Transforms a Meilisearch object into an URL encoded query string.
/// Transforms a Meilisearch object containing Lists into an URL encoded query string.
/// </summary>
/// <param name="source">Object to transform.</param>
/// <param name="bindingAttr">Binding flags.</param>
/// <returns>Returns an url encoded query string.</returns>
internal static string ToQueryString(this object source, BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
{
var values = source.GetType().GetProperties(bindingAttr)
.Where(p => p.GetValue(source, null) != null)
.Select(p =>
Uri.EscapeDataString(char.ToLowerInvariant(p.Name[0]) + p.Name.Substring(1)) + "=" + Uri.EscapeDataString(p.GetValue(source, null).ToString()));
var queryString = string.Join("&", values);
return queryString;
var values = new List<string>();
foreach (var field in source.GetType().GetProperties(bindingAttr))
{
if (field.GetValue(source, null) != null)
{
var isList = field.GetValue(source, null).GetType().IsGenericType && field.GetValue(source, null).GetType().GetGenericTypeDefinition() == typeof(List<>);
if (isList)
{
values.Add(Uri.EscapeDataString(char.ToLowerInvariant(field.Name[0]) + field.Name.Substring(1)) + "=" + string.Join(",", (List<string>)field.GetValue(source, null)));
}
else
{
values.Add(Uri.EscapeDataString(char.ToLowerInvariant(field.Name[0]) + field.Name.Substring(1)) + "=" + Uri.EscapeDataString(field.GetValue(source, null).ToString()));
}
}
}
return string.Join("&", values);
}
}
}
10 changes: 5 additions & 5 deletions src/Meilisearch/Index.Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<IEnumerable<string>> GetDisplayedAttributesAsync(CancellationT
public async Task<TaskInfo> UpdateDisplayedAttributesAsync(IEnumerable<string> displayedAttributes, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PostAsJsonAsync($"indexes/{Uid}/settings/displayed-attributes", displayedAttributes,
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/displayed-attributes", displayedAttributes,
Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task<string> GetDistinctAttributeAsync(CancellationToken cancellati
public async Task<TaskInfo> UpdateDistinctAttributeAsync(string distinctAttribute, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PostAsJsonAsync($"indexes/{Uid}/settings/distinct-attribute", distinctAttribute, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/distinct-attribute", distinctAttribute, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public async Task<IEnumerable<string>> GetFilterableAttributesAsync(Cancellation
public async Task<TaskInfo> UpdateFilterableAttributesAsync(IEnumerable<string> filterableAttributes, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PostAsJsonAsync($"indexes/{Uid}/settings/filterable-attributes", filterableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/filterable-attributes", filterableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<IEnumerable<string>> GetSearchableAttributesAsync(Cancellation
public async Task<TaskInfo> UpdateSearchableAttributesAsync(IEnumerable<string> searchableAttributes, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PostAsJsonAsync($"indexes/{Uid}/settings/searchable-attributes", searchableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/searchable-attributes", searchableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task<IEnumerable<string>> GetSortableAttributesAsync(CancellationTo
public async Task<TaskInfo> UpdateSortableAttributesAsync(IEnumerable<string> sortableAttributes, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PostAsJsonAsync($"indexes/{Uid}/settings/sortable-attributes", sortableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/sortable-attributes", sortableAttributes, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Loading

0 comments on commit cc6eddd

Please sign in to comment.