feat(search): add bidirectional domain aliases (taurine/taurin, carnitine) and include ingredientCardSlug
Deploy Canina / deploy (push) Successful in 2m8s

This commit is contained in:
Canina Automation committed 2026-10-27 11:49:15 +00:00
1 parent 66b9d75524
commit 8669d183d5
2 files changed
+38 -3

No files matched your search

+34 -2
View File
@@ -42,6 +42,26 @@ export const COMMON_STOP_WORDS = new Set([
"the", "a", "an", "and", "or", "for", "with", "in", "on", "at", "to", "of",
]);
export const SEARCH_EXPANSION_MAP: Record<string, string[]> = {
"تائورین": ["تورین", "taurine", "taurin"],
"تورین": ["تائورین", "taurine", "taurin"],
"taurine": ["تائورین", "تورین", "taurin"],
"taurin": ["تائورین", "تورین", "taurine"],
"کارنیتین": ["carnitine", "l-carnitine"],
"carnitine": ["کارنیتین", "l-carnitine"],
"گلوکزامین": ["گلوکوزامین", "glucosamine"],
"گلوکوزامین": ["گلوکزامین", "glucosamine"],
"glucosamine": ["گلوکوزامین", "گلوکزامین"],
"امگا": ["omega", "امگا ۳", "سالمون", "salmon"],
"omega": ["امگا", "امگا ۳", "salmon"],
"کندرویتین": ["chondroitin"],
"chondroitin": ["کندرویتین"],
"بیوتین": ["biotin"],
"biotin": ["بیوتین"],
"کلسیم": ["calcium"],
"calcium": ["کلسیم"],
};
/**
* Normalizes Persian and English text by standardizing characters,
* removing diacritics, half-spaces, punctuation, and folding case.
@@ -93,8 +113,20 @@ export function extractSearchTokens(rawQuery?: string | null): string[] {
);
// If filtering left nothing, return original non-empty tokens
const result = meaningful.length > 0 ? meaningful : rawTokens;
return Array.from(new Set(result));
const baseTokens = meaningful.length > 0 ? meaningful : rawTokens;
// Expand with domain aliases (e.g. تائورین <-> تورین <-> taurine)
const expanded = new Set<string>(baseTokens);
for (const token of baseTokens) {
const directAliases = SEARCH_EXPANSION_MAP[token] || SEARCH_EXPANSION_MAP[token.toLowerCase()];
if (directAliases) {
for (const alias of directAliases) {
expanded.add(normalizeSearchText(alias));
}
}
}
return Array.from(expanded).filter((t) => t.length >= 2);
}
export interface SearchScoreItem {
+4 -1
View File
@@ -86,7 +86,10 @@ export class ProductsService {
{
ingredientList: {
some: {
ingredient: { contains: token, mode },
OR: [
{ ingredient: { contains: token, mode } },
{ ingredientCardSlug: { contains: token, mode } },
],
},
},
},