From aa7a6d5f8cc4e5ff5c54dd2998e2a214a20402c2 Mon Sep 17 00:00:00 2001 From: qdequele Date: Thu, 2 Jan 2020 17:10:49 +0100 Subject: [PATCH] Rewrite the synonyms endpoint; fix #418 --- meilisearch-http/src/routes/mod.rs | 9 +++++---- meilisearch-http/src/routes/synonym.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index d15982350..efd90302a 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -76,11 +76,12 @@ pub fn load_routes(app: &mut tide::App) { .post(document::delete_multiple_documents); }); - router.at("/synonyms") - .get(synonym::get) - .post(synonym::update); - router.at("/settings").nest(|router| { + router.at("/synonyms") + .get(synonym::get) + .post(synonym::update) + .delete(synonym::delete); + router.at("/stop-words") .get(stop_words::get) .post(stop_words::update) diff --git a/meilisearch-http/src/routes/synonym.rs b/meilisearch-http/src/routes/synonym.rs index fc6c9c5f0..750f9cb87 100644 --- a/meilisearch-http/src/routes/synonym.rs +++ b/meilisearch-http/src/routes/synonym.rs @@ -71,3 +71,26 @@ pub async fn update(mut ctx: Context) -> SResult { .with_status(StatusCode::ACCEPTED) .into_response()) } + + +pub async fn delete(ctx: Context) -> SResult { + ctx.is_allowed(SettingsWrite)?; + + let index = ctx.index()?; + + let db = &ctx.state().db; + let mut writer = db.update_write_txn().map_err(ResponseError::internal)?; + + let synonyms_update = index.synonyms_update(); + + let update_id = synonyms_update + .finalize(&mut writer) + .map_err(ResponseError::internal)?; + + writer.commit().map_err(ResponseError::internal)?; + + let response_body = IndexUpdateResponse { update_id }; + Ok(tide::response::json(response_body) + .with_status(StatusCode::ACCEPTED) + .into_response()) +}