Ensure only last rows are queried for search

This commit is contained in:
2024-09-11 09:04:39 +02:00
parent ec5310a1f3
commit cbee5bd204
2 changed files with 4 additions and 2 deletions

View File

@@ -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)

View File

@@ -106,6 +106,7 @@
function setInputVal(food: main.Food) {
name = food.food;
per100 = String(food.per100);
amount = String(food.amount);
hiLiteIndex = null;
foodSearch = [];
}