feat: Eigene und zentrale Lebensmittel bearbeiten, mit Sichtbarkeit im Mapping
Nutzer können persönliche Foods anlegen und ändern; der Admin legt zentrale Einträge für alle an. Suche und Namens-Mapping berücksichtigen persönlich, zentral und BLS. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d35087ad84
commit
8b1e1da5d8
30 files changed
+1195
-120
No files matched your search
@@ -131,6 +131,8 @@ def score_name_match(query: str, name_de: str, name_en: str | None = None) -> in
|
||||
|
||||
|
||||
def _public(food: dict[str, Any], score: int) -> dict[str, Any]:
|
||||
from data_layer.food_visibility import visibility_of
|
||||
|
||||
return {
|
||||
"id": str(food["id"]),
|
||||
"bls_code": food.get("bls_code"),
|
||||
@@ -138,6 +140,7 @@ def _public(food: dict[str, Any], score: int) -> dict[str, Any]:
|
||||
"name_en": food.get("name_en"),
|
||||
"catalog_kind": food.get("catalog_kind"),
|
||||
"food_group": food.get("food_group"),
|
||||
"visibility": visibility_of(food),
|
||||
"score": score,
|
||||
}
|
||||
|
||||
@@ -163,7 +166,7 @@ def get_suggest_index(cur, profile_id: str | None) -> dict[str, Any]:
|
||||
def load_suggest_index(cur, profile_id: str | None) -> dict[str, Any]:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, bls_code, name_de, name_en, catalog_kind, food_group
|
||||
SELECT id, bls_code, name_de, name_en, catalog_kind, food_group, owner_profile_id
|
||||
FROM food_catalog
|
||||
WHERE is_active = true
|
||||
AND (owner_profile_id IS NULL OR owner_profile_id = %s)
|
||||
@@ -245,6 +248,11 @@ def _candidate_foods(index: dict[str, Any], query: str) -> list[dict[str, Any]]:
|
||||
return out[:MAX_CANDIDATES] if not number_tokens(query) else out
|
||||
|
||||
|
||||
def _vis_rank(food: dict[str, Any]) -> int:
|
||||
from data_layer.food_visibility import visibility_rank
|
||||
return visibility_rank(food)
|
||||
|
||||
|
||||
def suggest_for_name(index: dict[str, Any], query: str, limit: int = 3) -> dict[str, Any]:
|
||||
q = (query or "").strip()
|
||||
scored: list[tuple[int, int, dict]] = []
|
||||
@@ -253,7 +261,7 @@ def suggest_for_name(index: dict[str, Any], query: str, limit: int = 3) -> dict[
|
||||
if score < MIN_SCORE:
|
||||
continue
|
||||
scored.append((score, len(food.get("name_de") or ""), food))
|
||||
scored.sort(key=lambda x: (-x[0], x[1], x[2].get("name_de") or ""))
|
||||
scored.sort(key=lambda x: (-x[0], _vis_rank(x[2]), x[1], x[2].get("name_de") or ""))
|
||||
top = [_public(food, score) for score, _nlen, food in scored[: max(limit, 3)]]
|
||||
ambiguous = False
|
||||
if len(top) >= 2 and top[0]["score"] - top[1]["score"] <= 8 and top[1]["score"] >= 60:
|
||||
@@ -296,7 +304,7 @@ def suggest_catalog_foods_ranked(cur, query: str, profile_id: str | None, limit:
|
||||
if score < MIN_SCORE and not number_tokens(q):
|
||||
continue
|
||||
hits.append(_public(row, score or 40))
|
||||
hits.sort(key=lambda h: (-int(h.get("score") or 0), h.get("name_de") or ""))
|
||||
hits.sort(key=lambda h: (-int(h.get("score") or 0), _vis_rank(h), h.get("name_de") or ""))
|
||||
return hits[:limit]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user