Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,7 @@ facet_search_3: |-
ExhaustiveFacetCount: true
};
await client.Index("books").FacetSearchAsync("genres", query);
get_batch_1: |-
await client.GetBatchAsync(1);
get_all_batches_1: |-
await client.GetBatchesAsync();
61 changes: 61 additions & 0 deletions src/Meilisearch/BatchResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Meilisearch
{
/// <summary>
/// Batch Object
/// </summary>
public class BatchResult
{
/// <summary>
/// The unique sequential identifier of the batch.
/// </summary>
[JsonPropertyName("uid")]
public int Uid { get; }

/// <summary>
/// Detailed information on the batch progress.
/// </summary>
[JsonPropertyName("progress")]
public IReadOnlyCollection<IReadOnlyDictionary<string, dynamic>> Progress { get; }

/// <summary>
/// Detailed information on the batch.
/// </summary>
[JsonPropertyName("details")]
public IReadOnlyDictionary<string, dynamic> Details { get; }

/// <summary>
/// Detailed information on the stats.
/// </summary>
[JsonPropertyName("stats")]
public IReadOnlyDictionary<string, dynamic> Stats { get; }


/// <summary>
/// The total elapsed time the task spent in the processing state, in ISO 8601 format.
/// </summary>
[JsonPropertyName("duration")]

public string Duration { get; }
/// <summary>
/// The date and time when the task began processing, in RFC 3339 format.
/// </summary>
[JsonPropertyName("startedAt")]
public DateTime? StartedAt { get; }

/// <summary>
/// The date and time when the task finished processing, whether failed or succeeded, in RFC 3339 format.
/// </summary>
[JsonPropertyName("finishedAt")]
public DateTime? FinishedAt { get; }

/// <summary>
/// A string describing the logic behind the creation of the batch. Can contain useful information when diagnosing indexing performance issues.
/// </summary>
[JsonPropertyName("batchStrategy")]
public string BatchStrategy { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using System.Collections.Generic;

namespace Meilisearch
{
/// <summary>
/// Generic result class for resources.
/// When returning a list, Meilisearch stores the data in the "results" field, to allow better pagination.
/// </summary>
/// <typeparam name="T">Type of the Meilisearch server object. Ex: keys, indexes, ...</typeparam>
public class TasksResults<T> : Result<T>
public class ChunkedResults<T> : Result<T>
{
public TasksResults(T results, int? limit, int? from, int? next, int? total)
/// <summary>
/// Constructor for ChunkedResults.
/// </summary>
/// <param name="results">Results</param>
/// <param name="limit">Results limit</param>
/// <param name="from">Uid of the first item returned</param>
/// <param name="next">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</param>
/// <param name="total">Total number of items matching the filter or query</param>
public ChunkedResults(T results, int? limit, int? from, int? next, int? total)
: base(results, limit)
{
From = from;
Expand All @@ -28,7 +34,7 @@ public TasksResults(T results, int? limit, int? from, int? next, int? total)
public int? Next { get; }

/// <summary>
/// Gets total number of tasks.
/// Gets total number of results.
/// </summary>
public int? Total { get; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/Meilisearch/Index.Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class Index
/// <param name="query">Query parameters supports by the method.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns a list of the operations status.</returns>
public async Task<TasksResults<IEnumerable<TaskResource>>> GetTasksAsync(TasksQuery query = null, CancellationToken cancellationToken = default)
public async Task<ChunkedResults<IEnumerable<TaskResource>>> GetTasksAsync(TasksQuery query = null, CancellationToken cancellationToken = default)
{
if (query == null)
{
Expand Down
26 changes: 26 additions & 0 deletions src/Meilisearch/MeilisearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,32 @@ public string GenerateTenantToken(string apiKeyUid, TenantTokenRules searchRules
return TenantToken.GenerateToken(apiKeyUid, searchRules, apiKey ?? ApiKey, expiresAt);
}

/// <summary>
/// Gets the Batches.
/// </summary>
/// <param name="query">Query parameters supports by the method.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns a list of the batches.</returns>
public async Task<ChunkedResults<IEnumerable<BatchResult>>> GetBatchesAsync(BatchesQuery query = default, CancellationToken cancellationToken = default)
{
var uri = query.ToQueryString(uri: "batches");
return await _http.GetFromJsonAsync<ChunkedResults<IEnumerable<BatchResult>>>(uri, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

/// <summary>
/// Get a Batch.
/// </summary>
/// <param name="batchUid">UId of the Batch.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns the Batch.</returns>
public async Task<BatchResult> GetBatchAsync(int batchUid, CancellationToken cancellationToken = default)
{
var uri = $"batches/{batchUid}";
return await _http.GetFromJsonAsync<BatchResult>(uri, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

/// <summary>
/// Create a local reference to a task, without doing an HTTP call.
/// </summary>
Expand Down
96 changes: 96 additions & 0 deletions src/Meilisearch/QueryParameters/BatchesQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Meilisearch.QueryParameters
{
/// <summary>
/// A class that handles the creation of a query string for Batches.
/// </summary>
public class BatchesQuery
{
/// <summary>
/// Gets or sets the list of UIds to filter on.
/// </summary>
[JsonPropertyName("uids")]
public List<int> UIds { get; set; }

/// <summary>
/// Gets or sets the list of Batch UIds to filter on.
/// </summary>
[JsonPropertyName("batchUids")]
public List<int> BatchUIds { get; set; }

/// <summary>
/// Gets or sets the list of Index UIds to filter on.
/// </summary>
[JsonPropertyName("indexUids")]
public List<int> IndexUIds { get; set; }

/// <summary>
/// Gets or sets the list of statuses to filter on.
/// </summary>
[JsonPropertyName("statuses")]
public List<TaskInfoStatus> Statuses { get; set; }

/// <summary>
/// Gets or sets the list of types to filter on.
/// </summary>
[JsonPropertyName("types")]
public List<TaskInfoType> Types { get; set; }

/// <summary>
/// Gets or sets the Number of tasks to return.
/// </summary>
[JsonPropertyName("limit")]
public int? Limit { get; set; } = 20;

/// <summary>
/// Gets or sets the uid of the first task returned.
/// </summary>
[JsonPropertyName("from")]
public int? From { get; set; }

/// <summary>
/// Gets or set the order of the returned tasks.
/// </summary>
[JsonPropertyName("reverse")]
public bool Reverse { get; set; } = false;

/// <summary>
/// Gets or sets the date before the task is enqueued to filter.
/// </summary>
[JsonPropertyName("beforeEnqueuedAt")]
public DateTime? BeforeEnqueuedAt { get; set; }

/// <summary>
/// Gets or sets the date before the task is started to filter.
/// </summary>
[JsonPropertyName("beforeStartedAt")]
public DateTime? BeforeStartedAt { get; set; }

/// <summary>
/// Gets or sets the date before the task is finished to filter.
/// </summary>
[JsonPropertyName("beforeFinishedAt")]
public DateTime? BeforeFinishedAt { get; set; }

/// <summary>
/// Gets or sets the date after the task is enqueued to filter.
/// </summary>
[JsonPropertyName("afterEnqueuedAt")]
public DateTime? AfterEnqueuedAt { get; set; }

/// <summary>
/// Gets or sets the date after the task is started to filter.
/// </summary>
[JsonPropertyName("afterStartedAt")]
public DateTime? AfterStartedAt { get; set; }

/// <summary>
/// Gets or sets the date after the task is finished to filter.
/// </summary>
[JsonPropertyName("afterFinishedAt")]
public DateTime? AfterFinishedAt { get; set; }
}
}
8 changes: 4 additions & 4 deletions src/Meilisearch/TaskEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class TaskEndpoint
/// <param name="query">Query parameters supports by the method.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns a list of the tasks.</returns>
public async Task<TasksResults<IEnumerable<TaskResource>>> GetTasksAsync(TasksQuery query = default, CancellationToken cancellationToken = default)
public async Task<ChunkedResults<IEnumerable<TaskResource>>> GetTasksAsync(TasksQuery query = default, CancellationToken cancellationToken = default)
{
var uri = query.ToQueryString(uri: "tasks");
return await _http.GetFromJsonAsync<TasksResults<IEnumerable<TaskResource>>>(uri, cancellationToken: cancellationToken)
return await _http.GetFromJsonAsync<ChunkedResults<IEnumerable<TaskResource>>>(uri, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -79,9 +79,9 @@ public async Task<TaskResource> GetTaskAsync(int taskUid, CancellationToken canc
/// <param name="indexUid">Uid of the index.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns a list of tasks of an index.</returns>
public async Task<TasksResults<IEnumerable<TaskResource>>> GetIndexTasksAsync(string indexUid, CancellationToken cancellationToken = default)
public async Task<ChunkedResults<IEnumerable<TaskResource>>> GetIndexTasksAsync(string indexUid, CancellationToken cancellationToken = default)
{
return await _http.GetFromJsonAsync<TasksResults<IEnumerable<TaskResource>>>($"tasks?indexUid={indexUid}", cancellationToken: cancellationToken)
return await _http.GetFromJsonAsync<ChunkedResults<IEnumerable<TaskResource>>>($"tasks?indexUid={indexUid}", cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

Expand Down
Loading