implement delete documents

This commit is contained in:
mpostma 2021-03-04 15:59:18 +01:00
parent 181eaf95f5
commit ae5581d37c
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
3 changed files with 31 additions and 24 deletions

View File

@ -44,13 +44,11 @@ impl Data {
pub async fn delete_documents( pub async fn delete_documents(
&self, &self,
_index: impl AsRef<str> + Sync + Send + 'static, index: impl AsRef<str> + Sync + Send + 'static,
_document_ids: Vec<String>, document_ids: Vec<String>,
) -> anyhow::Result<UpdateStatus> { ) -> anyhow::Result<UpdateStatus> {
todo!() let update = self.index_controller.delete_documents(index.as_ref().to_string(), document_ids).await?;
//let index_controller = self.index_controller.clone(); Ok(update.into())
//let update = tokio::task::spawn_blocking(move || index_controller.delete_documents(index, document_ids)).await??;
//Ok(update.into())
} }
pub async fn delete_index( pub async fn delete_index(

View File

@ -7,8 +7,7 @@ mod update_handler;
use std::path::Path; use std::path::Path;
use actix_web::web::Bytes; use actix_web::web::{Bytes, Payload};
use actix_web::web::Payload;
use anyhow::Context; use anyhow::Context;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use futures::stream::StreamExt; use futures::stream::StreamExt;
@ -111,8 +110,19 @@ impl IndexController {
todo!() todo!()
} }
fn delete_documents(&self, index: String, document_ids: Vec<String>) -> anyhow::Result<UpdateStatus> { pub async fn delete_documents(&self, index: String, document_ids: Vec<String>) -> anyhow::Result<UpdateStatus> {
todo!() 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> { pub async fn update_settings(&self, index_uid: String, settings: Settings) -> anyhow::Result<UpdateStatus> {

View File

@ -229,21 +229,20 @@ async fn delete_documents(
path: web::Path<IndexParam>, path: web::Path<IndexParam>,
body: web::Json<Vec<Value>>, body: web::Json<Vec<Value>>,
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
todo!() let ids = body
//let ids = body .iter()
//.iter() .map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
//.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string())) .collect();
//.collect();
//match data.delete_documents(path.index_uid.clone(), ids).await { match data.delete_documents(path.index_uid.clone(), ids).await {
//Ok(result) => { Ok(result) => {
//let json = serde_json::to_string(&result).unwrap(); let json = serde_json::to_string(&result).unwrap();
//Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
//} }
//Err(e) => { Err(e) => {
//Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
//} }
//} }
} }
#[delete("/indexes/{index_uid}/documents", wrap = "Authentication::Private")] #[delete("/indexes/{index_uid}/documents", wrap = "Authentication::Private")]