mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 23:59:45 +02:00
feat: Improved Ingredient Matching (#2535)
* added normalization to foods and units
* changed search to reference new normalized fields
* fix tests
* added parsed food matching to backend
* prevent pagination from ordering when searching
* added extra fuzzy matching to sqlite ing matching
* added tests
* only apply search ordering when order_by is null
* enabled post-search fuzzy matching for postgres
* fixed postgres fuzzy search test
* idk why this is failing
* 🤦
* simplified frontend ing matching
and restored automatic unit creation
* tightened food fuzzy threshold
* change to rapidfuzz
* sped up fuzzy matching with process
* fixed units not matching by abbreviation
* fast return for exact matches
* replace db searching with pure fuzz
* added fuzzy normalization
* tightened unit fuzzy matching thresh
* cleaned up comments/var names
* ran matching logic through the dryer
* oops
* simplified order by application logic
This commit is contained in:
parent
084ad4228b
commit
2dfbe9f08d
17 changed files with 738 additions and 97 deletions
|
@ -25,13 +25,11 @@ def search_units(database: AllRepositories, unique_local_group_id: str) -> list[
|
|||
SaveIngredientUnit(
|
||||
group_id=unique_local_group_id,
|
||||
name="Table Spoon",
|
||||
description="unique description",
|
||||
abbreviation="tbsp",
|
||||
),
|
||||
SaveIngredientUnit(
|
||||
group_id=unique_local_group_id,
|
||||
name="Cup",
|
||||
description="A bucket that's full",
|
||||
),
|
||||
SaveIngredientUnit(
|
||||
group_id=unique_local_group_id,
|
||||
|
@ -45,6 +43,10 @@ def search_units(database: AllRepositories, unique_local_group_id: str) -> list[
|
|||
group_id=unique_local_group_id,
|
||||
name="Unit with a pretty cool name",
|
||||
),
|
||||
SaveIngredientUnit(
|
||||
group_id=unique_local_group_id,
|
||||
name="Unit with a correct horse battery staple",
|
||||
),
|
||||
]
|
||||
|
||||
# Add a bunch of units for stable randomization
|
||||
|
@ -64,16 +66,14 @@ def search_units(database: AllRepositories, unique_local_group_id: str) -> list[
|
|||
(random_string(), []),
|
||||
("Cup", ["Cup"]),
|
||||
("tbsp", ["Table Spoon"]),
|
||||
("unique description", ["Table Spoon"]),
|
||||
("very cool name", ["Unit with a very cool name", "Unit with a pretty cool name"]),
|
||||
('"Tea Spoon"', ["Tea Spoon"]),
|
||||
("full bucket", ["Cup"]),
|
||||
("correct staple", ["Unit with a correct horse battery staple"]),
|
||||
],
|
||||
ids=[
|
||||
"no_match",
|
||||
"search_by_name",
|
||||
"search_by_unit",
|
||||
"search_by_description",
|
||||
"match_order",
|
||||
"literal_search",
|
||||
"token_separation",
|
||||
|
@ -110,7 +110,7 @@ def test_fuzzy_search(
|
|||
|
||||
repo = database.ingredient_units.by_group(unique_local_group_id)
|
||||
pagination = PaginationQuery(page=1, per_page=-1, order_by="created_at", order_direction=OrderDirection.asc)
|
||||
results = repo.page_all(pagination, search="unique decsription").items
|
||||
results = repo.page_all(pagination, search="tabel spoone").items
|
||||
|
||||
assert results and results[0].name == "Table Spoon"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue