perf: use score_cutoff for fuzzy string matching (#2553)

This commit is contained in:
Max Bachmann 2023-09-16 22:24:45 +02:00 committed by GitHub
parent 9a04b11ee5
commit 15c6df88ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,15 +96,13 @@ class ABCIngredientParser(ABC):
return store_map[match_value]
# fuzzy match against food store
fuzz_result = process.extractOne(match_value, store_map.keys(), scorer=fuzz.ratio)
fuzz_result = process.extractOne(
match_value, store_map.keys(), scorer=fuzz.ratio, score_cutoff=fuzzy_match_threshold
)
if fuzz_result is None:
return None
choice, score, _ = fuzz_result
if score < fuzzy_match_threshold:
return None
else:
return store_map[choice]
return store_map[fuzz_result[0]]
def find_food_match(self, food: IngredientFood | CreateIngredientFood) -> IngredientFood | None:
if isinstance(food, IngredientFood):