From 097857afbb9925ad04059102bfe99ecd4669e50f Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:47:38 -0500 Subject: [PATCH 1/7] Made the results container generic and renamed to ChunkedResults. Batches and tasks share the same fields. --- src/Meilisearch/ChunkedResults.cs | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Meilisearch/ChunkedResults.cs diff --git a/src/Meilisearch/ChunkedResults.cs b/src/Meilisearch/ChunkedResults.cs new file mode 100644 index 00000000..a5eb04ed --- /dev/null +++ b/src/Meilisearch/ChunkedResults.cs @@ -0,0 +1,41 @@ +namespace Meilisearch +{ + /// + /// Generic result class for resources. + /// When returning a list, Meilisearch stores the data in the "results" field, to allow better pagination. + /// + /// Type of the Meilisearch server object. Ex: keys, indexes, ... + public class ChunkedResults : Result + { + /// + /// Constructor for ChunkedResults. + /// + /// Results + /// Results limit + /// Uid of the first item returned + /// Value passed to from to view the next “page” of results. When the value of next is null, there are no more items to view + /// Total number of items matching the filter or query + public ChunkedResults(T results, int? limit, int? from, int? next, int? total) + : base(results, limit) + { + From = from; + Next = next; + Total = total; + } + + /// + /// Gets from size. + /// + public int? From { get; } + + /// + /// Gets next size. + /// + public int? Next { get; } + + /// + /// Gets total number of results. + /// + public int? Total { get; } + } +} From 2cfcd565f41a0dc529946fc836d58c097af1c14c Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:47:49 -0500 Subject: [PATCH 2/7] BatchesQuery class --- .../QueryParameters/BatchesQuery.cs | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/Meilisearch/QueryParameters/BatchesQuery.cs diff --git a/src/Meilisearch/QueryParameters/BatchesQuery.cs b/src/Meilisearch/QueryParameters/BatchesQuery.cs new file mode 100644 index 00000000..e067d752 --- /dev/null +++ b/src/Meilisearch/QueryParameters/BatchesQuery.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Meilisearch.QueryParameters +{ + /// + /// A class that handles the creation of a query string for Batches. + /// + public class BatchesQuery + { + /// + /// Gets or sets the list of UIds to filter on. + /// + [JsonPropertyName("uids")] + public List UIds { get; set; } + + /// + /// Gets or sets the list of Batch UIds to filter on. + /// + [JsonPropertyName("batchUids")] + public List BatchUIds { get; set; } + + /// + /// Gets or sets the list of Index UIds to filter on. + /// + [JsonPropertyName("indexUids")] + public List IndexUIds { get; set; } + + /// + /// Gets or sets the list of statuses to filter on. + /// + [JsonPropertyName("statuses")] + public List Statuses { get; set; } + + /// + /// Gets or sets the list of types to filter on. + /// + [JsonPropertyName("types")] + public List Types { get; set; } + + /// + /// Gets or sets the Number of tasks to return. + /// + [JsonPropertyName("limit")] + public int? Limit { get; set; } = 20; + + /// + /// Gets or sets the uid of the first task returned. + /// + [JsonPropertyName("from")] + public int? From { get; set; } + + /// + /// Gets or set the order of the returned tasks. + /// + [JsonPropertyName("reverse")] + public bool Reverse { get; set; } = false; + + /// + /// Gets or sets the date before the task is enqueued to filter. + /// + [JsonPropertyName("beforeEnqueuedAt")] + public DateTime? BeforeEnqueuedAt { get; set; } + + /// + /// Gets or sets the date before the task is started to filter. + /// + [JsonPropertyName("beforeStartedAt")] + public DateTime? BeforeStartedAt { get; set; } + + /// + /// Gets or sets the date before the task is finished to filter. + /// + [JsonPropertyName("beforeFinishedAt")] + public DateTime? BeforeFinishedAt { get; set; } + + /// + /// Gets or sets the date after the task is enqueued to filter. + /// + [JsonPropertyName("afterEnqueuedAt")] + public DateTime? AfterEnqueuedAt { get; set; } + + /// + /// Gets or sets the date after the task is started to filter. + /// + [JsonPropertyName("afterStartedAt")] + public DateTime? AfterStartedAt { get; set; } + + /// + /// Gets or sets the date after the task is finished to filter. + /// + [JsonPropertyName("afterFinishedAt")] + public DateTime? AfterFinishedAt { get; set; } + } +} From 245ccbb0759fc80e4be2f1ab7594299ae8139aa3 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:48:07 -0500 Subject: [PATCH 3/7] BatchResource of returned object --- src/Meilisearch/BatchResource.cs | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Meilisearch/BatchResource.cs diff --git a/src/Meilisearch/BatchResource.cs b/src/Meilisearch/BatchResource.cs new file mode 100644 index 00000000..8841e170 --- /dev/null +++ b/src/Meilisearch/BatchResource.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace Meilisearch +{ + /// + /// Batch Object + /// + public class BatchResource + { + /// + /// The unique sequential identifier of the batch. + /// + [JsonPropertyName("uid")] + public int Uid { get; } + + /// + /// Detailed information on the batch progress. + /// + [JsonPropertyName("progress")] + public IReadOnlyCollection> Progress { get; } + + /// + /// Detailed information on the batch. + /// + [JsonPropertyName("details")] + public IReadOnlyDictionary Details { get; } + + /// + /// Detailed information on the stats. + /// + [JsonPropertyName("stats")] + public IReadOnlyDictionary Stats { get; } + + + /// + /// The total elapsed time the task spent in the processing state, in ISO 8601 format. + /// + [JsonPropertyName("duration")] + + public string Duration { get; } + /// + /// The date and time when the task began processing, in RFC 3339 format. + /// + [JsonPropertyName("startedAt")] + public DateTime? StartedAt { get; } + + /// + /// The date and time when the task finished processing, whether failed or succeeded, in RFC 3339 format. + /// + [JsonPropertyName("finishedAt")] + public DateTime? FinishedAt { get; } + + /// + /// A string describing the logic behind the creation of the batch. Can contain useful information when diagnosing indexing performance issues. + /// + [JsonPropertyName("batchStrategy")] + public string BatchStrategy { get; } + } +} From 7576305202567039824be92eb2c8714d58194121 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:48:44 -0500 Subject: [PATCH 4/7] Task result renamed and made generic as the response type is shared with Tasks --- src/Meilisearch/Index.Tasks.cs | 2 +- src/Meilisearch/TaskEndpoint.cs | 8 ++++---- src/Meilisearch/TasksResults.cs | 35 --------------------------------- 3 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 src/Meilisearch/TasksResults.cs diff --git a/src/Meilisearch/Index.Tasks.cs b/src/Meilisearch/Index.Tasks.cs index 0d7f1c8b..eb23d4f2 100644 --- a/src/Meilisearch/Index.Tasks.cs +++ b/src/Meilisearch/Index.Tasks.cs @@ -14,7 +14,7 @@ public partial class Index /// Query parameters supports by the method. /// The cancellation token for this call. /// Returns a list of the operations status. - public async Task>> GetTasksAsync(TasksQuery query = null, CancellationToken cancellationToken = default) + public async Task>> GetTasksAsync(TasksQuery query = null, CancellationToken cancellationToken = default) { if (query == null) { diff --git a/src/Meilisearch/TaskEndpoint.cs b/src/Meilisearch/TaskEndpoint.cs index e7f2fd32..73ea2e3b 100644 --- a/src/Meilisearch/TaskEndpoint.cs +++ b/src/Meilisearch/TaskEndpoint.cs @@ -24,10 +24,10 @@ public class TaskEndpoint /// Query parameters supports by the method. /// The cancellation token for this call. /// Returns a list of the tasks. - public async Task>> GetTasksAsync(TasksQuery query = default, CancellationToken cancellationToken = default) + public async Task>> GetTasksAsync(TasksQuery query = default, CancellationToken cancellationToken = default) { var uri = query.ToQueryString(uri: "tasks"); - return await _http.GetFromJsonAsync>>(uri, cancellationToken: cancellationToken) + return await _http.GetFromJsonAsync>>(uri, cancellationToken: cancellationToken) .ConfigureAwait(false); } @@ -79,9 +79,9 @@ public async Task GetTaskAsync(int taskUid, CancellationToken canc /// Uid of the index. /// The cancellation token for this call. /// Returns a list of tasks of an index. - public async Task>> GetIndexTasksAsync(string indexUid, CancellationToken cancellationToken = default) + public async Task>> GetIndexTasksAsync(string indexUid, CancellationToken cancellationToken = default) { - return await _http.GetFromJsonAsync>>($"tasks?indexUid={indexUid}", cancellationToken: cancellationToken) + return await _http.GetFromJsonAsync>>($"tasks?indexUid={indexUid}", cancellationToken: cancellationToken) .ConfigureAwait(false); } diff --git a/src/Meilisearch/TasksResults.cs b/src/Meilisearch/TasksResults.cs deleted file mode 100644 index 680c803a..00000000 --- a/src/Meilisearch/TasksResults.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; - -namespace Meilisearch -{ - /// - /// Generic result class for resources. - /// When returning a list, Meilisearch stores the data in the "results" field, to allow better pagination. - /// - /// Type of the Meilisearch server object. Ex: keys, indexes, ... - public class TasksResults : Result - { - public TasksResults(T results, int? limit, int? from, int? next, int? total) - : base(results, limit) - { - From = from; - Next = next; - Total = total; - } - - /// - /// Gets from size. - /// - public int? From { get; } - - /// - /// Gets next size. - /// - public int? Next { get; } - - /// - /// Gets total number of tasks. - /// - public int? Total { get; } - } -} From c0565e1e349aae4aa9bc7117b20d37669c27a0e9 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:48:58 -0500 Subject: [PATCH 5/7] batch endpoints implemented in client --- src/Meilisearch/MeilisearchClient.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Meilisearch/MeilisearchClient.cs b/src/Meilisearch/MeilisearchClient.cs index c926da86..b8834e07 100644 --- a/src/Meilisearch/MeilisearchClient.cs +++ b/src/Meilisearch/MeilisearchClient.cs @@ -422,6 +422,32 @@ public string GenerateTenantToken(string apiKeyUid, TenantTokenRules searchRules return TenantToken.GenerateToken(apiKeyUid, searchRules, apiKey ?? ApiKey, expiresAt); } + /// + /// Gets the Batches. + /// + /// Query parameters supports by the method. + /// The cancellation token for this call. + /// Returns a list of the batches. + public async Task>> GetBatchesAsync(BatchesQuery query = default, CancellationToken cancellationToken = default) + { + var uri = query.ToQueryString(uri: "batches"); + return await _http.GetFromJsonAsync>>(uri, cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + + /// + /// Get a Batch. + /// + /// UId of the Batch. + /// The cancellation token for this call. + /// Returns the Batch. + public async Task GetBatchAsync(int batchUid, CancellationToken cancellationToken = default) + { + var uri = $"batches/{batchUid}"; + return await _http.GetFromJsonAsync(uri, cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + /// /// Create a local reference to a task, without doing an HTTP call. /// From 4752043b77afccc5cad9343e097820ecbc163606 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 13:49:03 -0500 Subject: [PATCH 6/7] code samples --- .code-samples.meilisearch.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 454efca6..e51a6f45 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -843,3 +843,7 @@ facet_search_3: |- FacetQuery = "c" }; await client.Index("books").FacetSearchAsync("genres", query); +get_batch_1: |- + await client.GetBatchAsync(1); +get_all_batches_1: |- + await client.GetBatchesAsync(); From 7d5b77ad786b5db9be4c8fe3dd8021a85f397992 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 22 Oct 2025 14:00:17 -0500 Subject: [PATCH 7/7] Name adjustment to match library --- src/Meilisearch/{BatchResource.cs => BatchResult.cs} | 3 +-- src/Meilisearch/MeilisearchClient.cs | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) rename src/Meilisearch/{BatchResource.cs => BatchResult.cs} (97%) diff --git a/src/Meilisearch/BatchResource.cs b/src/Meilisearch/BatchResult.cs similarity index 97% rename from src/Meilisearch/BatchResource.cs rename to src/Meilisearch/BatchResult.cs index 8841e170..a7dde98e 100644 --- a/src/Meilisearch/BatchResource.cs +++ b/src/Meilisearch/BatchResult.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.Text.Json.Serialization; namespace Meilisearch @@ -8,7 +7,7 @@ namespace Meilisearch /// /// Batch Object /// - public class BatchResource + public class BatchResult { /// /// The unique sequential identifier of the batch. diff --git a/src/Meilisearch/MeilisearchClient.cs b/src/Meilisearch/MeilisearchClient.cs index 04f50cf6..e77f2c88 100644 --- a/src/Meilisearch/MeilisearchClient.cs +++ b/src/Meilisearch/MeilisearchClient.cs @@ -475,10 +475,10 @@ public string GenerateTenantToken(string apiKeyUid, TenantTokenRules searchRules /// Query parameters supports by the method. /// The cancellation token for this call. /// Returns a list of the batches. - public async Task>> GetBatchesAsync(BatchesQuery query = default, CancellationToken cancellationToken = default) + public async Task>> GetBatchesAsync(BatchesQuery query = default, CancellationToken cancellationToken = default) { var uri = query.ToQueryString(uri: "batches"); - return await _http.GetFromJsonAsync>>(uri, cancellationToken: cancellationToken) + return await _http.GetFromJsonAsync>>(uri, cancellationToken: cancellationToken) .ConfigureAwait(false); } @@ -488,10 +488,10 @@ public async Task>> GetBatchesAsync(Ba /// UId of the Batch. /// The cancellation token for this call. /// Returns the Batch. - public async Task GetBatchAsync(int batchUid, CancellationToken cancellationToken = default) + public async Task GetBatchAsync(int batchUid, CancellationToken cancellationToken = default) { var uri = $"batches/{batchUid}"; - return await _http.GetFromJsonAsync(uri, cancellationToken: cancellationToken) + return await _http.GetFromJsonAsync(uri, cancellationToken: cancellationToken) .ConfigureAwait(false); }