mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Introduce a new add or update documents PUT route
This commit is contained in:
parent
69832e8c70
commit
df066f4321
@ -151,7 +151,7 @@ fn infered_schema(document: &IndexMap<String, Value>) -> Option<meilidb_schema::
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn add_or_update_multiple_documents(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
async fn update_multiple_documents(mut ctx: Context<Data>, is_partial: bool) -> SResult<Response> {
|
||||
ctx.is_allowed(DocumentsWrite)?;
|
||||
|
||||
if !ctx.state().accept_updates() {
|
||||
@ -179,7 +179,11 @@ pub async fn add_or_update_multiple_documents(mut ctx: Context<Data>) -> SResult
|
||||
}
|
||||
}
|
||||
|
||||
let mut document_addition = index.documents_addition();
|
||||
let mut document_addition = if is_partial {
|
||||
index.documents_partial_addition()
|
||||
} else {
|
||||
index.documents_addition()
|
||||
};
|
||||
|
||||
for document in data {
|
||||
document_addition.update_document(document);
|
||||
@ -197,6 +201,14 @@ pub async fn add_or_update_multiple_documents(mut ctx: Context<Data>) -> SResult
|
||||
.into_response())
|
||||
}
|
||||
|
||||
pub async fn add_or_replace_multiple_documents(ctx: Context<Data>) -> SResult<Response> {
|
||||
update_multiple_documents(ctx, false).await
|
||||
}
|
||||
|
||||
pub async fn add_or_update_multiple_documents(ctx: Context<Data>) -> SResult<Response> {
|
||||
update_multiple_documents(ctx, true).await
|
||||
}
|
||||
|
||||
pub async fn delete_multiple_documents(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(DocumentsWrite)?;
|
||||
if !ctx.state().accept_updates() {
|
||||
|
@ -37,7 +37,8 @@ pub fn load_routes(app: &mut tide::App<Data>) {
|
||||
router
|
||||
.at("/")
|
||||
.get(document::browse_documents)
|
||||
.post(document::add_or_update_multiple_documents)
|
||||
.post(document::add_or_replace_multiple_documents)
|
||||
.put(document::add_or_update_multiple_documents)
|
||||
.delete(document::clear_all_documents);
|
||||
|
||||
router.at("/:identifier").nest(|router| {
|
||||
|
Loading…
Reference in New Issue
Block a user