Skip to content

Commit 9457894

Browse files
bors[bot]meili-botbidoubiwa
authored
Merge #370
370: Changes related to the next Meilisearch release (v0.30.0) r=bidoubiwa a=meili-bot Related to this issue: meilisearch/integration-guides#221 This PR: - gathers the changes related to the next Meilisearch release (v0.30.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.30.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.30.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
2 parents 7d3f1a7 + a04ae70 commit 9457894

9 files changed

+771
-92
lines changed

.code-samples.meilisearch.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,27 @@ get_all_tasks_1: |-
109109
.await
110110
.unwrap();
111111
get_all_tasks_filtering_1: |-
112-
let mut query = TasksQuery::new(&client)
113-
.with_index_uid(["movies"])
112+
let mut query = TasksSearchQuery::new(&client)
113+
.with_index_uids(["movies"])
114114
.execute()
115115
.await
116116
.unwrap();
117117
get_all_tasks_filtering_2: |-
118-
let mut query = TasksQuery::new(&client)
119-
.with_status(["succeeded", "failed"])
120-
.with_type(["documentAdditionOrUpdate"])
118+
let mut query = TasksSearchQuery::new(&client)
119+
.with_statuses(["succeeded", "failed"])
120+
.with_types(["documentAdditionOrUpdate"])
121121
.execute()
122122
.await
123123
.unwrap();
124124
get_all_tasks_paginating_1: |-
125-
let mut query = TasksQuery::new(&client)
125+
let mut query = TasksSearchQuery::new(&client)
126126
.with_limit(2)
127127
.with_from(10)
128128
.execute()
129129
.await
130130
.unwrap();
131131
get_all_tasks_paginating_2: |-
132-
let mut query = TasksQuery::new(&client)
132+
let mut query = TasksSearchQuery::new(&client)
133133
.with_limit(2)
134134
.from(8)
135135
.execute()
@@ -828,7 +828,7 @@ primary_field_guide_add_document_primary_key: |-
828828
getting_started_add_documents_md: |-
829829
```toml
830830
[dependencies]
831-
meilisearch-sdk = "0.20"
831+
meilisearch-sdk = "0.21"
832832
# futures: because we want to block on futures
833833
futures = "0.3"
834834
# serde: required if you are going to use documents

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "meilisearch-sdk"
3-
version = "0.20.1"
3+
version = "0.21.0"
44
authors = ["Mubelotix <[email protected]>"]
55
edition = "2018"
66
description = "Rust wrapper for the Meilisearch API. Meilisearch is a powerful, fast, open-source, easy to use and deploy search engine."

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:
5252

5353
```toml
5454
[dependencies]
55-
meilisearch-sdk = "0.20.1"
55+
meilisearch-sdk = "0.21.0"
5656
```
5757

5858
The following optional dependencies may also be useful:
@@ -244,7 +244,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
244244

245245
## 🤖 Compatibility with Meilisearch
246246

247-
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
247+
This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0).
248248

249249
## ⚙️ Contributing
250250

README.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:
5252

5353
```toml
5454
[dependencies]
55-
meilisearch-sdk = "0.20.1"
55+
meilisearch-sdk = "0.21.0"
5656
```
5757

5858
The following optional dependencies may also be useful:
@@ -99,7 +99,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
9999

100100
## 🤖 Compatibility with Meilisearch
101101

102-
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
102+
This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0).
103103

104104
## ⚙️ Contributing
105105

src/client.rs

+190-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::{collections::HashMap, time::Duration};
2-
3-
use serde::Deserialize;
1+
use serde::{Deserialize, Serialize};
42
use serde_json::{json, Value};
3+
use std::{collections::HashMap, time::Duration};
54
use time::OffsetDateTime;
65

76
use crate::{
@@ -10,7 +9,7 @@ use crate::{
109
key::{Key, KeyBuilder, KeyUpdater, KeysQuery, KeysResults},
1110
request::*,
1211
task_info::TaskInfo,
13-
tasks::{Task, TasksQuery, TasksResults},
12+
tasks::{Task, TasksCancelQuery, TasksDeleteQuery, TasksResults, TasksSearchQuery},
1413
utils::async_sleep,
1514
};
1615

@@ -21,6 +20,11 @@ pub struct Client {
2120
pub(crate) api_key: String,
2221
}
2322

23+
#[derive(Debug, Clone, Serialize, Deserialize)]
24+
pub struct SwapIndexes {
25+
pub indexes: (String, String),
26+
}
27+
2428
impl Client {
2529
/// Create a client using the specified server.
2630
/// Don't put a '/' at the end of the host.
@@ -331,6 +335,56 @@ impl Client {
331335
self.list_all_indexes_raw_with(indexes_query).await
332336
}
333337

338+
/// Swaps a list of two [Index]'es.
339+
///
340+
/// # Example
341+
///
342+
/// ```
343+
/// # use meilisearch_sdk::{client::*, indexes::*};
344+
/// #
345+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
346+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
347+
/// #
348+
/// # futures::executor::block_on(async move {
349+
/// // Create the client
350+
/// let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
351+
///
352+
/// let task_index_1 = client.create_index("swap_index_1", None).await.unwrap();
353+
/// let task_index_2 = client.create_index("swap_index_2", None).await.unwrap();
354+
///
355+
/// // Wait for the task to complete
356+
/// task_index_2.wait_for_completion(&client, None, None).await.unwrap();
357+
///
358+
/// let task = client
359+
/// .swap_indexes([&SwapIndexes {
360+
/// indexes: (
361+
/// "swap_index_1".to_string(),
362+
/// "swap_index_2".to_string(),
363+
/// ),
364+
/// }])
365+
/// .await
366+
/// .unwrap();
367+
///
368+
/// # client.index("swap_index_1").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
369+
/// # client.index("swap_index_2").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
370+
/// # });
371+
/// ```
372+
pub async fn swap_indexes(
373+
&self,
374+
indexes: impl IntoIterator<Item = &SwapIndexes>,
375+
) -> Result<TaskInfo, Error> {
376+
request::<(), Vec<&SwapIndexes>, TaskInfo>(
377+
&format!("{}/swap-indexes", self.host),
378+
&self.api_key,
379+
Method::Post {
380+
query: (),
381+
body: indexes.into_iter().collect(),
382+
},
383+
202,
384+
)
385+
.await
386+
}
387+
334388
/// Get stats of all indexes.
335389
///
336390
/// # Example
@@ -756,16 +810,16 @@ impl Client {
756810
/// # futures::executor::block_on(async move {
757811
/// # let client = client::Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
758812
///
759-
/// let mut query = tasks::TasksQuery::new(&client);
760-
/// query.with_index_uid(["get_tasks_with"]);
813+
/// let mut query = tasks::TasksSearchQuery::new(&client);
814+
/// query.with_index_uids(["get_tasks_with"]);
761815
/// let tasks = client.get_tasks_with(&query).await.unwrap();
762816
/// # });
763817
/// ```
764818
pub async fn get_tasks_with(
765819
&self,
766-
tasks_query: &TasksQuery<'_>,
820+
tasks_query: &TasksSearchQuery<'_>,
767821
) -> Result<TasksResults, Error> {
768-
let tasks = request::<&TasksQuery, (), TasksResults>(
822+
let tasks = request::<&TasksSearchQuery, (), TasksResults>(
769823
&format!("{}/tasks", self.host),
770824
&self.api_key,
771825
Method::Get { query: tasks_query },
@@ -776,6 +830,77 @@ impl Client {
776830
Ok(tasks)
777831
}
778832

833+
/// Cancel tasks with filters [TasksCancelQuery]
834+
///
835+
/// # Example
836+
///
837+
/// ```
838+
/// # use meilisearch_sdk::*;
839+
/// #
840+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
841+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
842+
/// #
843+
/// # futures::executor::block_on(async move {
844+
/// # let client = client::Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
845+
///
846+
/// let mut query = tasks::TasksCancelQuery::new(&client);
847+
/// query.with_index_uids(["movies"]);
848+
///
849+
/// let res = client.cancel_tasks_with(&query).await.unwrap();
850+
/// # });
851+
/// ```
852+
pub async fn cancel_tasks_with(
853+
&self,
854+
filters: &TasksCancelQuery<'_>,
855+
) -> Result<TaskInfo, Error> {
856+
let tasks = request::<&TasksCancelQuery, (), TaskInfo>(
857+
&format!("{}/tasks/cancel", self.host),
858+
&self.api_key,
859+
Method::Post {
860+
query: filters,
861+
body: (),
862+
},
863+
200,
864+
)
865+
.await?;
866+
867+
Ok(tasks)
868+
}
869+
870+
/// Delete tasks with filters [TasksDeleteQuery]
871+
///
872+
/// # Example
873+
///
874+
/// ```
875+
/// # use meilisearch_sdk::*;
876+
/// #
877+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
878+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
879+
/// #
880+
/// # futures::executor::block_on(async move {
881+
/// # let client = client::Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
882+
///
883+
/// let mut query = tasks::TasksDeleteQuery::new(&client);
884+
/// query.with_index_uids(["movies"]);
885+
///
886+
/// let res = client.delete_tasks_with(&query).await.unwrap();
887+
/// # });
888+
/// ```
889+
pub async fn delete_tasks_with(
890+
&self,
891+
filters: &TasksDeleteQuery<'_>,
892+
) -> Result<TaskInfo, Error> {
893+
let tasks = request::<&TasksDeleteQuery, (), TaskInfo>(
894+
&format!("{}/tasks", self.host),
895+
&self.api_key,
896+
Method::Delete { query: filters },
897+
200,
898+
)
899+
.await?;
900+
901+
Ok(tasks)
902+
}
903+
779904
/// Get all tasks from the server.
780905
///
781906
/// # Example
@@ -791,7 +916,6 @@ impl Client {
791916
/// let tasks = client.get_tasks().await.unwrap();
792917
///
793918
/// # assert!(tasks.results.len() > 0);
794-
/// # client.index("get_tasks").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
795919
/// # });
796920
/// ```
797921
pub async fn get_tasks(&self) -> Result<TasksResults, Error> {
@@ -894,8 +1018,62 @@ mod tests {
8941018
use crate::{
8951019
client::*,
8961020
key::{Action, KeyBuilder},
1021+
tasks::TasksSearchQuery,
8971022
};
8981023

1024+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1025+
struct Document {
1026+
id: String,
1027+
}
1028+
1029+
#[meilisearch_test]
1030+
async fn test_swapping_two_indexes(client: Client) {
1031+
let index_1 = client.index("test_swapping_two_indexes_1");
1032+
let index_2 = client.index("test_swapping_two_indexes_2");
1033+
1034+
let t0 = index_1
1035+
.add_documents(
1036+
&[Document {
1037+
id: "1".to_string(),
1038+
}],
1039+
None,
1040+
)
1041+
.await
1042+
.unwrap();
1043+
1044+
index_2
1045+
.add_documents(
1046+
&[Document {
1047+
id: "2".to_string(),
1048+
}],
1049+
None,
1050+
)
1051+
.await
1052+
.unwrap();
1053+
1054+
t0.wait_for_completion(&client, None, None).await.unwrap();
1055+
1056+
let task = client
1057+
.swap_indexes([&SwapIndexes {
1058+
indexes: (
1059+
"test_swapping_two_indexes_1".to_string(),
1060+
"test_swapping_two_indexes_2".to_string(),
1061+
),
1062+
}])
1063+
.await
1064+
.unwrap();
1065+
task.wait_for_completion(&client, None, None).await.unwrap();
1066+
1067+
let document = index_1.get_document("2").await.unwrap();
1068+
1069+
assert_eq!(
1070+
Document {
1071+
id: "2".to_string()
1072+
},
1073+
document
1074+
);
1075+
}
1076+
8991077
#[meilisearch_test]
9001078
async fn test_methods_has_qualified_version_as_header() {
9011079
let mock_server_url = &mockito::server_url();
@@ -971,15 +1149,15 @@ mod tests {
9711149
#[meilisearch_test]
9721150
async fn test_get_tasks(client: Client) {
9731151
let tasks = client.get_tasks().await.unwrap();
974-
assert!(tasks.results.len() >= 2);
1152+
assert!(tasks.limit == 20);
9751153
}
9761154

9771155
#[meilisearch_test]
9781156
async fn test_get_tasks_with_params(client: Client) {
979-
let query = TasksQuery::new(&client);
1157+
let query = TasksSearchQuery::new(&client);
9801158
let tasks = client.get_tasks_with(&query).await.unwrap();
9811159

982-
assert!(tasks.results.len() >= 2);
1160+
assert!(tasks.limit == 20);
9831161
}
9841162

9851163
#[meilisearch_test]

src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub enum ErrorCode {
139139
MissingAuthorizationHeader,
140140
TaskNotFound,
141141
DumpNotFound,
142+
MssingMasterKey,
142143
NoSpaceLeftOnDevice,
143144
PayloadTooLarge,
144145
UnretrievableDocument,
@@ -156,6 +157,12 @@ pub enum ErrorCode {
156157
InvalidApiKeyIndexes,
157158
InvalidApiKeyExpiresAt,
158159
ApiKeyNotFound,
160+
InvalidTaskTypesFilter,
161+
InvalidTaskStatusesFilter,
162+
InvalidTaskCanceledByFilter,
163+
InvalidTaskUidsFilter,
164+
InvalidTaskDateFilter,
165+
MissingTaskFilters,
159166

160167
/// That's unexpected. Please open a GitHub issue after ensuring you are
161168
/// using the supported version of the Meilisearch server.

0 commit comments

Comments
 (0)