mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 00:55:00 +08:00
implement delete documents
This commit is contained in:
parent
181eaf95f5
commit
ae5581d37c
@ -44,13 +44,11 @@ impl Data {
|
||||
|
||||
pub async fn delete_documents(
|
||||
&self,
|
||||
_index: impl AsRef<str> + Sync + Send + 'static,
|
||||
_document_ids: Vec<String>,
|
||||
index: impl AsRef<str> + Sync + Send + 'static,
|
||||
document_ids: Vec<String>,
|
||||
) -> anyhow::Result<UpdateStatus> {
|
||||
todo!()
|
||||
//let index_controller = self.index_controller.clone();
|
||||
//let update = tokio::task::spawn_blocking(move || index_controller.delete_documents(index, document_ids)).await??;
|
||||
//Ok(update.into())
|
||||
let update = self.index_controller.delete_documents(index.as_ref().to_string(), document_ids).await?;
|
||||
Ok(update.into())
|
||||
}
|
||||
|
||||
pub async fn delete_index(
|
||||
|
@ -7,8 +7,7 @@ mod update_handler;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use actix_web::web::Bytes;
|
||||
use actix_web::web::Payload;
|
||||
use actix_web::web::{Bytes, Payload};
|
||||
use anyhow::Context;
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures::stream::StreamExt;
|
||||
@ -111,8 +110,19 @@ impl IndexController {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn delete_documents(&self, index: String, document_ids: Vec<String>) -> anyhow::Result<UpdateStatus> {
|
||||
todo!()
|
||||
pub async fn delete_documents(&self, index: String, document_ids: Vec<String>) -> anyhow::Result<UpdateStatus> {
|
||||
let uuid = self.uuid_resolver.resolve(index).await.unwrap().unwrap();
|
||||
let meta = UpdateMeta::DeleteDocuments;
|
||||
let (sender, receiver) = mpsc::channel(10);
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
let json = serde_json::to_vec(&document_ids).unwrap();
|
||||
let bytes = Bytes::from(json);
|
||||
let _ = sender.send(Ok(bytes)).await;
|
||||
});
|
||||
|
||||
let status = self.update_handle.update(meta, receiver, uuid).await?;
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
pub async fn update_settings(&self, index_uid: String, settings: Settings) -> anyhow::Result<UpdateStatus> {
|
||||
|
@ -229,21 +229,20 @@ async fn delete_documents(
|
||||
path: web::Path<IndexParam>,
|
||||
body: web::Json<Vec<Value>>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
todo!()
|
||||
//let ids = body
|
||||
//.iter()
|
||||
//.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
|
||||
//.collect();
|
||||
let ids = body
|
||||
.iter()
|
||||
.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
|
||||
.collect();
|
||||
|
||||
//match data.delete_documents(path.index_uid.clone(), ids).await {
|
||||
//Ok(result) => {
|
||||
//let json = serde_json::to_string(&result).unwrap();
|
||||
//Ok(HttpResponse::Ok().body(json))
|
||||
//}
|
||||
//Err(e) => {
|
||||
//Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
|
||||
//}
|
||||
//}
|
||||
match data.delete_documents(path.index_uid.clone(), ids).await {
|
||||
Ok(result) => {
|
||||
let json = serde_json::to_string(&result).unwrap();
|
||||
Ok(HttpResponse::Ok().body(json))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[delete("/indexes/{index_uid}/documents", wrap = "Authentication::Private")]
|
||||
|
Loading…
Reference in New Issue
Block a user