Skip to content

Commit 0fad2af

Browse files
committed
feat: add custom metadata support for document tasks
1 parent f0746ec commit 0fad2af

File tree

10 files changed

+343
-130
lines changed

10 files changed

+343
-130
lines changed

examples/cli-app-with-awc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async fn build_index(client: &Client<AwcClient>) {
186186
// add the documents
187187
let result = client
188188
.index("clothes")
189-
.add_or_update(&clothes, Some("id"))
189+
.add_or_update(&clothes, Some("id"), None)
190190
.await
191191
.unwrap()
192192
.wait_for_completion(client, None, None)

examples/cli-app/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async fn build_index() {
110110
// add the documents
111111
let result = CLIENT
112112
.index("clothes")
113-
.add_or_update(&clothes, Some("id"))
113+
.add_or_update(&clothes, Some("id"), None)
114114
.await
115115
.unwrap()
116116
.wait_for_completion(&CLIENT, None, None)

examples/web_app_graphql/src/graphql_schema/users/query/search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl SearchUsers {
2424
match client.get_index("users").await {
2525
//If getting the index is successful, we add documents to it
2626
Ok(index) => {
27-
index.add_documents(&list_users, Some("id")).await?;
27+
index.add_documents(&list_users, Some("id"), None).await?;
2828
}
2929

3030
//If getting the index fails, we create it and then add documents to the new index
@@ -33,7 +33,7 @@ impl SearchUsers {
3333
let task = task.wait_for_completion(client, None, None).await?;
3434
let index = task.try_make_index(client).unwrap();
3535

36-
index.add_documents(&list_users, Some("id")).await?;
36+
index.add_documents(&list_users, Some("id"), None).await?;
3737
}
3838
}
3939

src/client.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<Http: HttpClient> Client<Http> {
168168
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
169169
/// let mut movies = client.index("search");
170170
/// # // add some documents
171-
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
171+
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name"), None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
172172
///
173173
/// let search_query_1 = SearchQuery::new(&movies)
174174
/// .with_query("Interstellar")
@@ -909,7 +909,7 @@ impl<Http: HttpClient> Client<Http> {
909909
/// let task = movies.add_documents(&[
910910
/// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() },
911911
/// Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() },
912-
/// ], None).await.unwrap();
912+
/// ], None, None).await.unwrap();
913913
///
914914
/// let status = client.wait_for_task(task, None, None).await.unwrap();
915915
///
@@ -961,7 +961,7 @@ impl<Http: HttpClient> Client<Http> {
961961
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
962962
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
963963
/// # let index = client.create_index("movies_get_task", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap();
964-
/// let task = index.delete_all_documents().await.unwrap();
964+
/// let task = index.delete_all_documents(None).await.unwrap();
965965
///
966966
/// let task = client.get_task(task).await.unwrap();
967967
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
@@ -1545,7 +1545,7 @@ mod tests {
15451545

15461546
use meilisearch_test_macro::meilisearch_test;
15471547

1548-
use crate::{client::*, key::Action, reqwest::qualified_version};
1548+
use crate::{key::Action, reqwest::qualified_version};
15491549

15501550
#[derive(Debug, Serialize, Deserialize, PartialEq)]
15511551
struct Document {
@@ -1563,6 +1563,7 @@ mod tests {
15631563
id: "1".to_string(),
15641564
}],
15651565
None,
1566+
None,
15661567
)
15671568
.await
15681569
.unwrap();
@@ -1573,6 +1574,7 @@ mod tests {
15731574
id: "2".to_string(),
15741575
}],
15751576
None,
1577+
None,
15761578
)
15771579
.await
15781580
.unwrap();

src/documents.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
141141
/// id: String,
142142
/// }
143143
/// # let index = client.index("document_query_execute");
144-
/// # index.add_or_replace(&[MyObject{id:"1".to_string(), kind:String::from("a kind")},MyObject{id:"2".to_string(), kind:String::from("some kind")}], None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
144+
/// # index.add_or_replace(&[MyObject{id:"1".to_string(), kind:String::from("a kind")},MyObject{id:"2".to_string(), kind:String::from("some kind")}], None, None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
145145
///
146146
/// let document = DocumentQuery::new(&index).with_fields(["id"])
147147
/// .execute::<MyObjectReduced>("1")
@@ -413,7 +413,17 @@ impl<'a, Http: HttpClient> DocumentDeletionQuery<'a, Http> {
413413
}
414414

415415
pub async fn execute<T: DeserializeOwned + 'static>(&self) -> Result<TaskInfo, Error> {
416-
self.index.delete_documents_with(self).await
416+
self.execute_with_custom_metadata::<T>(None).await
417+
}
418+
419+
/// Same as [`DocumentDeletionQuery::execute`] but allows passing `custom_metadata` for the created task.
420+
pub async fn execute_with_custom_metadata<T: DeserializeOwned + 'static>(
421+
&self,
422+
custom_metadata: Option<&'a str>,
423+
) -> Result<TaskInfo, Error> {
424+
self.index
425+
.delete_documents_with(self, custom_metadata)
426+
.await
417427
}
418428
}
419429

@@ -475,6 +485,7 @@ mod tests {
475485
},
476486
],
477487
None,
488+
None,
478489
)
479490
.await?;
480491

@@ -526,7 +537,7 @@ mod tests {
526537
let mut query = DocumentDeletionQuery::new(&index);
527538
query.with_filter("id = 1");
528539
index
529-
.delete_documents_with(&query)
540+
.delete_documents_with(&query, None)
530541
.await?
531542
.wait_for_completion(&client, None, None)
532543
.await?;
@@ -555,7 +566,7 @@ mod tests {
555566
let mut query = DocumentDeletionQuery::new(&index);
556567
query.with_filter("id = 1");
557568
let error = index
558-
.delete_documents_with(&query)
569+
.delete_documents_with(&query, None)
559570
.await?
560571
.wait_for_completion(&client, None, None)
561572
.await?;

0 commit comments

Comments
 (0)