From 2b5b76e3f54888c26fa8ad8074678e1451ace34c Mon Sep 17 00:00:00 2001 From: Whatsuup Date: Mon, 14 Aug 2023 13:55:11 +0200 Subject: [PATCH] added and tested different thresholds for food, line and canteen names --- .../src/layer/data/database/mealplan_management.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/layer/data/database/mealplan_management.rs b/backend/src/layer/data/database/mealplan_management.rs index dab51943..f4f9b319 100644 --- a/backend/src/layer/data/database/mealplan_management.rs +++ b/backend/src/layer/data/database/mealplan_management.rs @@ -10,7 +10,9 @@ pub struct PersistentMealplanManagementData { pub(super) pool: Pool, } -const THRESHOLD: f32 = 0.785; +const THRESHOLD_MEAL: f32 = 0.785; +const THRESHOLD_LINE: f32 = 0.894; +const THRESHOLD_CANTEEN: f32 = 0.8515; #[async_trait] #[allow(clippy::missing_panics_doc)] // necessary because sqlx macro sometimes create unreachable panics? @@ -33,7 +35,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData { async fn get_similar_canteen(&self, similar_name: &str) -> Result> { sqlx::query_scalar!( "SELECT canteen_id FROM canteen WHERE similarity(name, $1) >= $2 ORDER BY similarity(name, $1) DESC", - similar_name, THRESHOLD + similar_name, THRESHOLD_CANTEEN ) .fetch_optional(&self.pool) .await @@ -43,7 +45,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData { async fn get_similar_line(&self, similar_name: &str, canteen_id: Uuid) -> Result> { sqlx::query_scalar!( "SELECT line_id FROM line WHERE similarity(name, $1) >= $3 AND canteen_id = $2 ORDER BY similarity(name, $1) DESC", - similar_name, canteen_id, THRESHOLD + similar_name, canteen_id, THRESHOLD_LINE ) .fetch_optional(&self.pool) .await @@ -93,7 +95,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData { .copied() .map(Additive::to_db_string) .collect::>() as _, - THRESHOLD + THRESHOLD_MEAL ) .fetch_optional(&self.pool) .await @@ -143,7 +145,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData { .copied() .map(Additive::to_db_string) .collect::>() as _, - THRESHOLD + THRESHOLD_MEAL ) .fetch_optional(&self.pool) .await