diff --git a/foodservice.go b/foodservice.go index 973dcb1..e0a93dd 100644 --- a/foodservice.go +++ b/foodservice.go @@ -68,14 +68,15 @@ func (s *FoodService) GetLastPer100(name string) ([]FoodSearch, error) { query := fmt.Sprintf(` with search_results as ( - select word, score, f.rowid, f.* + select word, score, f.rowid, f.*, + row_number() over (partition by f.food order by score asc, date desc) as rn from foodfix inner join food f on f.food == word where word MATCH ? ) select %s, score from search_results -group by food +where rn = 1 order by score asc, date desc limit %d `, foodColumns, Settings.SearchLimit) diff --git a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte index 13e2297..a22b7b6 100644 --- a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte +++ b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte @@ -106,6 +106,7 @@ function setInputVal(food: main.Food) { name = food.food; per100 = String(food.per100); + amount = String(food.amount); hiLiteIndex = null; foodSearch = []; }