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
CI / Typecheck, test & build (push) Failing after 42s
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user