mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
restore document deletion routes
This commit is contained in:
parent
c32012c44a
commit
b9d189bf12
@ -7,7 +7,7 @@ use meilisearch_lib::MeiliSearch;
|
|||||||
use meilisearch_lib::index_controller::{DocumentAdditionFormat, Update};
|
use meilisearch_lib::index_controller::{DocumentAdditionFormat, Update};
|
||||||
use milli::update::IndexDocumentsMethod;
|
use milli::update::IndexDocumentsMethod;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
//use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
@ -76,14 +76,14 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
.route(web::get().to(get_all_documents))
|
.route(web::get().to(get_all_documents))
|
||||||
.route(web::post().guard(guard_json).to(add_documents))
|
.route(web::post().guard(guard_json).to(add_documents))
|
||||||
.route(web::put().guard(guard_json).to(update_documents))
|
.route(web::put().guard(guard_json).to(update_documents))
|
||||||
//.route(web::delete().to(clear_all_documents)),
|
.route(web::delete().to(clear_all_documents)),
|
||||||
)
|
)
|
||||||
// this route needs to be before the /documents/{document_id} to match properly
|
// this route needs to be before the /documents/{document_id} to match properly
|
||||||
//.service(web::resource("/delete-batch").route(web::post().to(delete_documents)))
|
.service(web::resource("/delete-batch").route(web::post().to(delete_documents)))
|
||||||
.service(
|
.service(
|
||||||
web::resource("/{document_id}")
|
web::resource("/{document_id}")
|
||||||
.route(web::get().to(get_document))
|
.route(web::get().to(get_document))
|
||||||
//.route(web::delete().to(delete_document)),
|
.route(web::delete().to(delete_document)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,16 +100,16 @@ pub async fn get_document(
|
|||||||
Ok(HttpResponse::Ok().json(document))
|
Ok(HttpResponse::Ok().json(document))
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub async fn delete_document(
|
pub async fn delete_document(
|
||||||
//data: GuardedData<Private, MeiliSearch>,
|
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||||
//path: web::Path<DocumentParam>,
|
path: web::Path<DocumentParam>,
|
||||||
//) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
//let update_status = data
|
let DocumentParam { document_id, index_uid } = path.into_inner();
|
||||||
//.delete_documents(path.index_uid.clone(), vec![path.document_id.clone()])
|
let update = Update::DeleteDocuments(vec![document_id]);
|
||||||
//.await?;
|
let update_status = meilisearch.register_update(index_uid, update).await?;
|
||||||
//debug!("returns: {:?}", update_status);
|
debug!("returns: {:?}", update_status);
|
||||||
//Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
//}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
@ -200,31 +200,33 @@ pub async fn update_documents(
|
|||||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub async fn delete_documents(
|
pub async fn delete_documents(
|
||||||
//data: GuardedData<Private, MeiliSearch>,
|
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||||
//path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
//body: web::Json<Vec<Value>>,
|
body: web::Json<Vec<Value>>,
|
||||||
//) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
//debug!("called with params: {:?}", body);
|
debug!("called with params: {:?}", body);
|
||||||
//let ids = body
|
let ids = body
|
||||||
//.iter()
|
.iter()
|
||||||
//.map(|v| {
|
.map(|v| {
|
||||||
//v.as_str()
|
v.as_str()
|
||||||
//.map(String::from)
|
.map(String::from)
|
||||||
//.unwrap_or_else(|| v.to_string())
|
.unwrap_or_else(|| v.to_string())
|
||||||
//})
|
})
|
||||||
//.collect();
|
.collect();
|
||||||
|
|
||||||
//let update_status = data.delete_documents(path.index_uid.clone(), ids).await?;
|
let update = Update::DeleteDocuments(ids);
|
||||||
//debug!("returns: {:?}", update_status);
|
let update_status = meilisearch.register_update(path.into_inner().index_uid, update).await?;
|
||||||
//Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
debug!("returns: {:?}", update_status);
|
||||||
//}
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
|
}
|
||||||
|
|
||||||
//pub async fn clear_all_documents(
|
pub async fn clear_all_documents(
|
||||||
//data: GuardedData<Private, MeiliSearch>,
|
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||||
//path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
//) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
//let update_status = data.clear_documents(path.index_uid.clone()).await?;
|
let update = Update::ClearDocuments;
|
||||||
//debug!("returns: {:?}", update_status);
|
let update_status = meilisearch.register_update(path.into_inner().index_uid, update).await?;
|
||||||
//Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
debug!("returns: {:?}", update_status);
|
||||||
//}
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
|
}
|
||||||
|
@ -72,10 +72,10 @@ impl From<&UpdateStatus> for UpdateType {
|
|||||||
RegisterUpdate::Settings(settings) => UpdateType::Settings {
|
RegisterUpdate::Settings(settings) => UpdateType::Settings {
|
||||||
settings: settings.clone(),
|
settings: settings.clone(),
|
||||||
},
|
},
|
||||||
//UpdateMeta::ClearDocuments => UpdateType::ClearAll,
|
RegisterUpdate::ClearDocuments => UpdateType::ClearAll,
|
||||||
//UpdateMeta::DeleteDocuments { ids } => UpdateType::DocumentsDeletion {
|
RegisterUpdate::DeleteDocuments(ids) => UpdateType::DocumentsDeletion {
|
||||||
//number: Some(ids.len()),
|
number: Some(ids.len()),
|
||||||
//},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,22 @@ impl Index {
|
|||||||
let settings = settings.clone().check();
|
let settings = settings.clone().check();
|
||||||
self.update_settings(&mut txn, &settings, update_builder)
|
self.update_settings(&mut txn, &settings, update_builder)
|
||||||
},
|
},
|
||||||
|
RegisterUpdate::ClearDocuments => {
|
||||||
|
let builder = update_builder.clear_documents(&mut txn, self);
|
||||||
|
let _count = builder.execute()?;
|
||||||
|
Ok(UpdateResult::Other)
|
||||||
|
},
|
||||||
|
RegisterUpdate::DeleteDocuments(ids) => {
|
||||||
|
let mut builder = update_builder.delete_documents(&mut txn, self)?;
|
||||||
|
|
||||||
|
// We ignore unexisting document ids
|
||||||
|
ids.iter().for_each(|id| {
|
||||||
|
builder.delete_external_id(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
let deleted = builder.execute()?;
|
||||||
|
Ok(UpdateResult::DocumentDeletion { deleted })
|
||||||
|
}
|
||||||
};
|
};
|
||||||
txn.commit()?;
|
txn.commit()?;
|
||||||
result
|
result
|
||||||
@ -241,18 +257,6 @@ impl Index {
|
|||||||
Ok(UpdateResult::DocumentsAddition(addition))
|
Ok(UpdateResult::DocumentsAddition(addition))
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn clear_documents(&self, update_builder: UpdateBuilder) -> Result<UpdateResult> {
|
|
||||||
//// We must use the write transaction of the update here.
|
|
||||||
//let mut wtxn = self.write_txn()?;
|
|
||||||
//let builder = update_builder.clear_documents(&mut wtxn, self);
|
|
||||||
|
|
||||||
//let _count = builder.execute()?;
|
|
||||||
|
|
||||||
//wtxn.commit()
|
|
||||||
//.and(Ok(UpdateResult::Other))
|
|
||||||
//.map_err(Into::into)
|
|
||||||
//}
|
|
||||||
|
|
||||||
fn update_settings<'a, 'b>(
|
fn update_settings<'a, 'b>(
|
||||||
&'a self,
|
&'a self,
|
||||||
txn: &mut heed::RwTxn<'a, 'b>,
|
txn: &mut heed::RwTxn<'a, 'b>,
|
||||||
@ -322,25 +326,6 @@ impl Index {
|
|||||||
|
|
||||||
Ok(UpdateResult::Other)
|
Ok(UpdateResult::Other)
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn delete_documents(
|
|
||||||
//&self,
|
|
||||||
//document_ids: &[String],
|
|
||||||
//update_builder: UpdateBuilder,
|
|
||||||
//) -> Result<UpdateResult> {
|
|
||||||
//let mut txn = self.write_txn()?;
|
|
||||||
//let mut builder = update_builder.delete_documents(&mut txn, self)?;
|
|
||||||
|
|
||||||
//// We ignore unexisting document ids
|
|
||||||
//document_ids.iter().for_each(|id| {
|
|
||||||
//builder.delete_external_id(id);
|
|
||||||
//});
|
|
||||||
|
|
||||||
//let deleted = builder.execute()?;
|
|
||||||
//txn.commit()
|
|
||||||
//.and(Ok(UpdateResult::DocumentDeletion { deleted }))
|
|
||||||
//.map_err(Into::into)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -95,6 +95,8 @@ pub struct Stats {
|
|||||||
#[derive(derivative::Derivative)]
|
#[derive(derivative::Derivative)]
|
||||||
#[derivative(Debug)]
|
#[derivative(Debug)]
|
||||||
pub enum Update {
|
pub enum Update {
|
||||||
|
DeleteDocuments(Vec<String>),
|
||||||
|
ClearDocuments,
|
||||||
Settings(Settings<Unchecked>),
|
Settings(Settings<Unchecked>),
|
||||||
DocumentAddition {
|
DocumentAddition {
|
||||||
#[derivative(Debug="ignore")]
|
#[derivative(Debug="ignore")]
|
||||||
|
@ -49,12 +49,14 @@ pub fn create_update_handler(
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum RegisterUpdate {
|
pub enum RegisterUpdate {
|
||||||
|
DeleteDocuments(Vec<String>),
|
||||||
DocumentAddition {
|
DocumentAddition {
|
||||||
primary_key: Option<String>,
|
primary_key: Option<String>,
|
||||||
method: IndexDocumentsMethod,
|
method: IndexDocumentsMethod,
|
||||||
content_uuid: Uuid,
|
content_uuid: Uuid,
|
||||||
},
|
},
|
||||||
Settings(Settings<Unchecked>),
|
Settings(Settings<Unchecked>),
|
||||||
|
ClearDocuments,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper type to implement read on a `Stream<Result<Bytes, Error>>`.
|
/// A wrapper type to implement read on a `Stream<Result<Bytes, Error>>`.
|
||||||
@ -210,6 +212,8 @@ impl UpdateLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Update::Settings(settings) => RegisterUpdate::Settings(settings),
|
Update::Settings(settings) => RegisterUpdate::Settings(settings),
|
||||||
|
Update::ClearDocuments => RegisterUpdate::ClearDocuments,
|
||||||
|
Update::DeleteDocuments(ids) => RegisterUpdate::DeleteDocuments(ids),
|
||||||
};
|
};
|
||||||
|
|
||||||
let store = self.store.clone();
|
let store = self.store.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user