Skip to content

Commit

Permalink
Merge branch 'main' into meili-bot/add-yamllint
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema authored Aug 2, 2023
2 parents 41b9381 + f131295 commit fc77d41
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 52 deletions.
84 changes: 80 additions & 4 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@
# the documentation on build
# You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples
---
faceted_search_2: |-
await client.MultiSearchAsync(new MultiSearchQuery()
{
Queries = new System.Collections.Generic.List<SearchQuery>()
{
new SearchQuery() {
IndexUid = "books",
Filter = new[] {
new[] {"language = English", "language = French"},
new[] {"genres = Fiction"}
},
Facets = new[] { "language", "genres", "author", "format" }
},
new SearchQuery() {
IndexUid = "books",
Filter = new[] {
new[] {"genres = Fiction"}
},
Facets = new[] { "language" }
},
new SearchQuery() {
IndexUid = "books",
Filter = new[] {
new[] {"language = English", "language = French"}
},
Facets = new[] { "genres" }
}
}
});
getting_started_faceting: |-
var faceting = new Faceting {
MaxValuesPerFacet = 2
Expand Down Expand Up @@ -80,7 +109,13 @@ 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: |-
await client.Index("movies").GetDocumentsAsync<Movie>(new DocumentsQuery() { Limit = 2 });
await client.Index("movies").GetDocumentsAsync<Movie>(new DocumentsQuery() { Limit = 2, Filter = "genres = action" });
get_documents_post_1: |-
await client.Index("movies").GetDocumentsAsync<Movie>(new DocumentsQuery() {
Limit = 3,
Fields = new List<string> { "title", "genres", "rating", "language"},
Filter = "(rating > 3 AND (genres=Adventure OR genres=Fiction)) AND language=English"
});
add_or_replace_documents_1: |-
var movie = new[]
{
Expand All @@ -104,8 +139,10 @@ delete_all_documents_1: |-
await client.Index("movies").DeleteAllDocumentsAsync();
delete_one_document_1: |-
await client.Index("movies").DeleteOneDocumentAsync("25684");
delete_documents_1: |-
delete_documents_by_batch_1: |-
await client.Index("movies").DeleteDocumentsAsync(new[] { "23488", "153738", "437035", "363869" });
delete_documents_by_filter_1: |-
await client.Index("movies").DeleteDocumentsAsync(new DeleteDocumentsQuery() { Filter = "genres = action OR genres = adventure" });
search_post_1: |-
await client.Index("movies").SearchAsync<Movie>("American ninja");
get_task_1: |
Expand Down Expand Up @@ -325,7 +362,7 @@ getting_started_add_documents_md: |-
{
static async Task Main(string[] args)
{
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "aSampleMasterKey");
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
Expand Down Expand Up @@ -425,7 +462,7 @@ getting_started_communicating_with_a_protected_instance: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "apiKey");
await client.Index("Movies").SearchAsync<Movie>("");
faceted_search_update_settings_1: |-
filtering_update_settings_1: |-
await client.Index("movies").UpdateFilterableAttributesAsync(new [] { "director", "genres" });
faceted_search_filter_1: |-
SearchQuery filters = new SearchQuery()
Expand All @@ -450,6 +487,15 @@ faceted_search_walkthrough_filter_1: |-
Filter = "(genre = 'Horror' AND genre = 'Mystery') OR director = 'Jordan Peele'"
};
await client.Index("movies").SearchAsync<Movie>("thriller", sq);
faceted_search_update_settings_1: |-
List<string> attributes = new() { "genres", "rating", "language" };
TaskInfo result = await client.Index("books").UpdateFilterableAttributesAsync(attributes);
faceted_search_1: |-
var sq = new SearchQuery
{
Facets = new string[] { "genres", "rating", "language" }
};
await client.Index("books").SearchAsync<Book>("classic", sq);
add_movies_json_1: |-
// Make sure to add this using to your code
using System.IO;
Expand Down Expand Up @@ -541,6 +587,15 @@ geosearch_guide_sort_usage_2: |-
}
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
geosearch_guide_filter_usage_3: |-
SearchQuery filters = new SearchQuery()
{
Sort = new string[] {
"_geoBoundingBox([45.494181, 9.179175], [45.449484, 9.214024])",
"rating:desc"
}
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
primary_field_guide_create_index_primary_key: |-
TaskInfo task = await client.CreateIndexAsync("books", "reference_number");
Expand Down Expand Up @@ -688,3 +743,24 @@ update_faceting_settings_1: |-
await client.Index("movies").UpdateFacetingAsync(faceting);
reset_faceting_settings_1: |-
await client.Index("movies").ResetFacetingAsync();
multi_search_1: |-
await client.MultiSearchAsync(new MultiSearchQuery()
{
Queries = new System.Collections.Generic.List<SearchQuery>()
{
new SearchQuery() {
IndexUid = "movies",
Q = "booh",
Limit = 5
},
new SearchQuery() {
IndexUid = "movies",
Q = "nemo",
Limit = 5
},
new SearchQuery() {
IndexUid = "movie_ratings",
Q = "us",
},
}
});
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MEILISEARCH_VERSION=v1.1.0
MEILISEARCH_VERSION=v1.2.0
PROXIED_MEILISEARCH=http://nginx/api/
MEILISEARCH_URL=http://meilisearch:7700
6 changes: 2 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: "3.1.x"
dotnet-version: "6.0.x"
- name: Install dependencies
run: dotnet restore
- name: Build
Expand All @@ -39,9 +39,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: "3.1.x"
- name: Install dotnet-format
run: dotnet tool install -g dotnet-format
dotnet-version: "6.0.x"
- name: Check with dotnet-format
run: dotnet format --version
- name: Check with dotnet-format
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can set up your local environment natively or using `docker`, check out the

Example of running all the checks with docker:
```bash
docker-compose run --rm package bash -c "dotnet test && dotnet format --check Meilisearch.sln"
docker-compose run --rm package bash -c "dotnet test && dotnet format --verbosity normal --verify-no-changes"
```

To install dependencies:
Expand Down
4 changes: 0 additions & 4 deletions Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<h4 align="center">
<a href="https://github.com/meilisearch/meilisearch">Meilisearch</a> |
<a href="https://www.meilisearch.com/pricing?utm_campaign=oss&utm_source=integration&utm_medium=meilisearch-dotnet">Meilisearch Cloud</a> |
<a href="https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-dotnet">Meilisearch Cloud</a> |
<a href="https://www.meilisearch.com/docs">Documentation</a> |
<a href="https://discord.meilisearch.com">Discord</a> |
<a href="https://roadmap.meilisearch.com/tabs/1-under-consideration">Roadmap</a> |
Expand Down Expand Up @@ -51,7 +51,7 @@ For general information on how to use Meilisearch—such as our API reference, t

## ⚡ Supercharge your Meilisearch experience

Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/pricing?utm_campaign=oss&utm_source=integration&utm_medium=meilisearch-dotnet). No credit card required.
Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-dotnet). Get started with a 14-day free trial! No credit card required.

## 🔧 Installation

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ volumes:

services:
package:
build: .
image: mcr.microsoft.com/dotnet/sdk:6.0
tty: true
stdin_open: true
working_dir: /home/package
Expand Down
6 changes: 6 additions & 0 deletions src/Meilisearch/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ internal static class Constants
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};

internal static string VersionErrorHintMessage(string message, string method)
{
return
$"{message}\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that ${method} call requires.";
}
}
}
88 changes: 74 additions & 14 deletions src/Meilisearch/Index.Documents.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -69,7 +70,8 @@ public async Task<TaskInfo> AddDocumentsJsonAsync(string documents, string prima
/// <param name="csvDelimiter">One ASCII character used to customize the delimiter for CSV. Comma used by default.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns the task info.</returns>
public async Task<TaskInfo> AddDocumentsCsvAsync(string documents, string primaryKey = default, char csvDelimiter = default,
public async Task<TaskInfo> AddDocumentsCsvAsync(string documents, string primaryKey = default,
char csvDelimiter = default,
CancellationToken cancellationToken = default)
{
var uri = $"indexes/{Uid}/documents";
Expand All @@ -79,6 +81,7 @@ public async Task<TaskInfo> AddDocumentsCsvAsync(string documents, string primar
{
queryString.Add("primaryKey", primaryKey);
}

if (csvDelimiter != default)
{
queryString.Add("csvDelimiter", csvDelimiter.ToString());
Expand Down Expand Up @@ -146,12 +149,14 @@ public async Task<IEnumerable<TaskInfo>> AddDocumentsInBatchesAsync<T>(IEnumerab
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns the task list.</returns>
public async Task<IEnumerable<TaskInfo>> AddDocumentsCsvInBatchesAsync(string documents,
int batchSize = 1000, string primaryKey = default, char csvDelimiter = default, CancellationToken cancellationToken = default)
int batchSize = 1000, string primaryKey = default, char csvDelimiter = default,
CancellationToken cancellationToken = default)
{
var tasks = new List<TaskInfo>();
foreach (var chunk in documents.GetCsvChunks(batchSize))
{
tasks.Add(await AddDocumentsCsvAsync(chunk, primaryKey, csvDelimiter, cancellationToken).ConfigureAwait(false));
tasks.Add(await AddDocumentsCsvAsync(chunk, primaryKey, csvDelimiter, cancellationToken)
.ConfigureAwait(false));
}

return tasks;
Expand Down Expand Up @@ -196,7 +201,9 @@ public async Task<TaskInfo> UpdateDocumentsAsync<T>(IEnumerable<T> documents, st
uri = $"{uri}?{new { primaryKey = primaryKey }.ToQueryString()}";
}

responseMessage = await _http.PutJsonCustomAsync(uri, documents, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken).ConfigureAwait(false);
responseMessage = await _http
.PutJsonCustomAsync(uri, documents, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken)
.ConfigureAwait(false);

return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
Expand Down Expand Up @@ -340,7 +347,8 @@ public async Task<IEnumerable<TaskInfo>> UpdateDocumentsNdjsonInBatchesAsync(str
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <typeparam name="T">Type of the document.</typeparam>
/// <returns>Returns the document, with the according type if the object is available.</returns>
public async Task<T> GetDocumentAsync<T>(string documentId, List<string> fields = default, CancellationToken cancellationToken = default)
public async Task<T> GetDocumentAsync<T>(string documentId, List<string> fields = default,
CancellationToken cancellationToken = default)
{
var uri = $"indexes/{Uid}/documents/{documentId}";
if (fields != null)
Expand All @@ -361,7 +369,8 @@ public async Task<T> GetDocumentAsync<T>(string documentId, List<string> fields
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <typeparam name="T">Type to return for document.</typeparam>
/// <returns>Type if the object is availble.</returns>
public async Task<T> GetDocumentAsync<T>(int documentId, List<string> fields = default, CancellationToken cancellationToken = default)
public async Task<T> GetDocumentAsync<T>(int documentId, List<string> fields = default,
CancellationToken cancellationToken = default)
{
return await GetDocumentAsync<T>(documentId.ToString(), fields, cancellationToken);
}
Expand All @@ -376,14 +385,37 @@ public async Task<T> GetDocumentAsync<T>(int documentId, List<string> fields = d
public async Task<ResourceResults<IEnumerable<T>>> GetDocumentsAsync<T>(DocumentsQuery query = default,
CancellationToken cancellationToken = default)
{
var uri = $"indexes/{Uid}/documents";
if (query != null)
if (query != null && query.Filter != null)
{
uri = $"{uri}?{query.ToQueryString()}";
try
{
//Use the fetch route
var uri = $"indexes/{Uid}/documents/fetch";
var result = await _http.PostAsJsonAsync(uri, query, Constants.JsonSerializerOptionsRemoveNulls,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await result.Content
.ReadFromJsonAsync<ResourceResults<IEnumerable<T>>>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (MeilisearchCommunicationError e)
{
throw new MeilisearchCommunicationError(
Constants.VersionErrorHintMessage(e.Message, nameof(GetDocumentsAsync)), e);
}
}
else
{
var uri = $"indexes/{Uid}/documents";
if (query != null)
{
uri = $"{uri}?{query.ToQueryString()}";
}

return await _http
.GetFromJsonAsync<ResourceResults<IEnumerable<T>>>(uri, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

return await _http.GetFromJsonAsync<ResourceResults<IEnumerable<T>>>(uri, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -430,6 +462,33 @@ await _http.PostAsJsonAsync($"indexes/{Uid}/documents/delete-batch", documentIds
.ConfigureAwait(false);
}

/// <summary>
/// Delete documents from an index based on a filter.
/// </summary>
/// <remarks>Available ONLY with Meilisearch v1.2 and newer.</remarks>
/// <param name="query">A hash containing a filter that should match documents.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Return the task info.</returns>
public async Task<TaskInfo> DeleteDocumentsAsync(DeleteDocumentsQuery query,
CancellationToken cancellationToken = default)
{
try
{
var httpresponse =
await _http.PostAsJsonAsync($"indexes/{Uid}/documents/delete", query,
Constants.JsonSerializerOptionsRemoveNulls,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
return await httpresponse.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (MeilisearchCommunicationError e)
{
throw new MeilisearchCommunicationError(
Constants.VersionErrorHintMessage(e.Message, nameof(DeleteDocumentsAsync)), e);
}
}

/// <summary>
/// Delete documents in batch.
/// </summary>
Expand Down Expand Up @@ -477,15 +536,16 @@ public async Task<ISearchable<T>> SearchAsync<T>(string query,
body = searchAttributes;
body.Q = query;
}

body.IndexUid = default;

var responseMessage = await _http.PostAsJsonAsync($"indexes/{Uid}/search", body,
Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);

return await responseMessage.Content
.ReadFromJsonAsync<ISearchable<T>>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
.ReadFromJsonAsync<ISearchable<T>>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
}
}
Loading

0 comments on commit fc77d41

Please sign in to comment.