Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/cli-app-with-awc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async fn build_index(client: &Client<AwcClient>) {
// add the documents
let result = client
.index("clothes")
.add_or_update(&clothes, Some("id"))
.add_or_update(&clothes, Some("id"), None)
.await
.unwrap()
.wait_for_completion(client, None, None)
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async fn build_index() {
// add the documents
let result = CLIENT
.index("clothes")
.add_or_update(&clothes, Some("id"))
.add_or_update(&clothes, Some("id"), None)
.await
.unwrap()
.wait_for_completion(&CLIENT, None, None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl SearchUsers {
match client.get_index("users").await {
//If getting the index is successful, we add documents to it
Ok(index) => {
index.add_documents(&list_users, Some("id")).await?;
index.add_documents(&list_users, Some("id"), None).await?;
}

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

index.add_documents(&list_users, Some("id")).await?;
index.add_documents(&list_users, Some("id"), None).await?;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<Http: HttpClient> Client<Http> {
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let mut movies = client.index("search");
/// # // add some documents
/// # 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();
/// # 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();
///
/// let search_query_1 = SearchQuery::new(&movies)
/// .with_query("Interstellar")
Expand Down Expand Up @@ -909,7 +909,7 @@ impl<Http: HttpClient> Client<Http> {
/// let task = movies.add_documents(&[
/// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() },
/// Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() },
/// ], None).await.unwrap();
/// ], None, None).await.unwrap();
///
/// let status = client.wait_for_task(task, None, None).await.unwrap();
///
Expand Down Expand Up @@ -961,7 +961,7 @@ impl<Http: HttpClient> Client<Http> {
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # let index = client.create_index("movies_get_task", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap();
/// let task = index.delete_all_documents().await.unwrap();
/// let task = index.delete_all_documents(None).await.unwrap();
///
/// let task = client.get_task(task).await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
Expand Down Expand Up @@ -1545,7 +1545,7 @@ mod tests {

use meilisearch_test_macro::meilisearch_test;

use crate::{client::*, key::Action, reqwest::qualified_version};
use crate::{key::Action, reqwest::qualified_version};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Document {
Expand All @@ -1563,6 +1563,7 @@ mod tests {
id: "1".to_string(),
}],
None,
None,
)
.await
.unwrap();
Expand All @@ -1573,6 +1574,7 @@ mod tests {
id: "2".to_string(),
}],
None,
None,
)
.await
.unwrap();
Expand Down
19 changes: 15 additions & 4 deletions src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
/// id: String,
/// }
/// # let index = client.index("document_query_execute");
/// # 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();
/// # 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();
///
/// let document = DocumentQuery::new(&index).with_fields(["id"])
/// .execute::<MyObjectReduced>("1")
Expand Down Expand Up @@ -413,7 +413,17 @@ impl<'a, Http: HttpClient> DocumentDeletionQuery<'a, Http> {
}

pub async fn execute<T: DeserializeOwned + 'static>(&self) -> Result<TaskInfo, Error> {
self.index.delete_documents_with(self).await
self.execute_with_custom_metadata::<T>(None).await
}

/// Same as [`DocumentDeletionQuery::execute`] but allows passing `custom_metadata` for the created task.
pub async fn execute_with_custom_metadata<T: DeserializeOwned + 'static>(
&self,
custom_metadata: Option<&'a str>,
) -> Result<TaskInfo, Error> {
self.index
.delete_documents_with(self, custom_metadata)
.await
}
}

Expand Down Expand Up @@ -475,6 +485,7 @@ mod tests {
},
],
None,
None,
)
.await?;

Expand Down Expand Up @@ -526,7 +537,7 @@ mod tests {
let mut query = DocumentDeletionQuery::new(&index);
query.with_filter("id = 1");
index
.delete_documents_with(&query)
.delete_documents_with(&query, None)
.await?
.wait_for_completion(&client, None, None)
.await?;
Expand Down Expand Up @@ -555,7 +566,7 @@ mod tests {
let mut query = DocumentDeletionQuery::new(&index);
query.with_filter("id = 1");
let error = index
.delete_documents_with(&query)
.delete_documents_with(&query, None)
.await?
.wait_for_completion(&client, None, None)
.await?;
Expand Down
Loading
Loading