fix(reco): fria sökord + mjuk-filter så råvaru-sökning (kyckling) ger rätt recept (MIKRO 60)
CI / Typecheck, test & build (push) Failing after 42s

This commit is contained in:
Sven (AAMOS AI)
2026-08-14 20:28:56 +07:00
parent 83dd0bb215
commit 33c72ddacd
2 changed files with 47 additions and 2 deletions
+16 -1
View File
@@ -393,7 +393,22 @@ export async function recommendationRoutes(app: FastifyInstance) {
const weights = personalizationEnabled
? viewWeights(q.view)
: depersonalize(viewWeights(q.view));
let recommendations = rankAll(scoredCandidates, ctx, weights, q.limit);
// Om användaren sökte specifikt (t.ex. "kyckling") visa matchande recept först.
let pool = scoredCandidates;
if (craving && (craving.keywords.length > 0 || craving.cuisine)) {
const matches = scoredCandidates.filter((c) => {
const title = c.titleSv.toLowerCase();
const tagSet = new Set<string>(c.tags as unknown as string[]);
return (
(!!craving.cuisine && c.cuisine === craving.cuisine) ||
craving.keywords.some((k) => title.includes(k) || tagSet.has(k))
);
});
if (matches.length > 0) pool = matches; // annars behåll alla (aldrig tomt)
}
let recommendations = rankAll(pool, ctx, weights, q.limit);
// --- 9. AAMOS-omrankning bakom feature flag (aldrig obligatorisk) ---
if (await app.flags.isEnabled("ai_rerank", req.userId)) {