Skip to content

Commit

Permalink
added and tested different thresholds for food, line and canteen names
Browse files Browse the repository at this point in the history
  • Loading branch information
Whatsuup committed Aug 14, 2023
1 parent d1f5d8f commit 2b5b76e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/src/layer/data/database/mealplan_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub struct PersistentMealplanManagementData {
pub(super) pool: Pool<Postgres>,
}

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?
Expand All @@ -33,7 +35,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData {
async fn get_similar_canteen(&self, similar_name: &str) -> Result<Option<Uuid>> {
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
Expand All @@ -43,7 +45,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData {
async fn get_similar_line(&self, similar_name: &str, canteen_id: Uuid) -> Result<Option<Uuid>> {
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
Expand Down Expand Up @@ -93,7 +95,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData {
.copied()
.map(Additive::to_db_string)
.collect::<Vec<_>>() as _,
THRESHOLD
THRESHOLD_MEAL
)
.fetch_optional(&self.pool)
.await
Expand Down Expand Up @@ -143,7 +145,7 @@ impl MealplanManagementDataAccess for PersistentMealplanManagementData {
.copied()
.map(Additive::to_db_string)
.collect::<Vec<_>>() as _,
THRESHOLD
THRESHOLD_MEAL
)
.fetch_optional(&self.pool)
.await
Expand Down

0 comments on commit 2b5b76e

Please sign in to comment.