Spaces:
Running
Running
v7: lead Catalogue AI matches for cabinet-hardware queries (khóa/tay nắm/thùng rác/kệ...)
Browse files
index.ts
CHANGED
|
@@ -838,9 +838,9 @@ async function serverSearchProducts(q: string, limit: number): Promise<any[]> {
|
|
| 838 |
scored.sort((a, b) => b.s - a.s);
|
| 839 |
const ranked = scored.slice(0, limit).map(x => formatProduct(x.p, x.p._idx ?? 0));
|
| 840 |
// Catalogue AI (Malloca/Imudex/H2) fallback: VAIX lacks Imudex products, so
|
| 841 |
-
// queries like "khóa điện tử" / "tay nắm" / "thùng rác" must
|
| 842 |
-
//
|
| 843 |
-
//
|
| 844 |
const cat = await serverSearchCatai(q, limit);
|
| 845 |
if (cat.length) {
|
| 846 |
const seen = new Set(ranked.map(r => String(r.sku || "") + String(r.name || "")));
|
|
@@ -850,14 +850,18 @@ async function serverSearchProducts(q: string, limit: number): Promise<any[]> {
|
|
| 850 |
if (seen.has(k)) continue;
|
| 851 |
added.push(c);
|
| 852 |
seen.add(k);
|
| 853 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
}
|
| 855 |
-
// Imudex-family keywords: prefer exact CATAI name matches on top of VAIX noise.
|
| 856 |
-
const fam = /khoa|khoá|kenangha|taynam|banle|ray|thungrac|giag|giatri|giavi|ke[ -]?gia|ke[ -]?xi|ke[ -]?dao|ke[ -]?chen|ke[ -]?bat|ke[ -]?xoong|dia|chen|bat|combo|lock|smart/i.test(qNorm);
|
| 857 |
-
const boosted = added.filter(c => fam);
|
| 858 |
-
const rest = added.filter(c => !fam);
|
| 859 |
-
for (const c of boosted) ranked.unshift(c);
|
| 860 |
-
for (const c of rest) ranked.push(c);
|
| 861 |
}
|
| 862 |
return ranked.slice(0, limit);
|
| 863 |
}
|
|
|
|
| 838 |
scored.sort((a, b) => b.s - a.s);
|
| 839 |
const ranked = scored.slice(0, limit).map(x => formatProduct(x.p, x.p._idx ?? 0));
|
| 840 |
// Catalogue AI (Malloca/Imudex/H2) fallback: VAIX lacks Imudex products, so
|
| 841 |
+
// queries like "khóa điện tử" / "tay nắm" / "thùng rác" must surface Imudex
|
| 842 |
+
// items. If the query matches an Imudex-family keyword or VAIX had no strong
|
| 843 |
+
// hit, lead with the Catalogue AI matches (deduped) and keep VAIX as tail.
|
| 844 |
const cat = await serverSearchCatai(q, limit);
|
| 845 |
if (cat.length) {
|
| 846 |
const seen = new Set(ranked.map(r => String(r.sku || "") + String(r.name || "")));
|
|
|
|
| 850 |
if (seen.has(k)) continue;
|
| 851 |
added.push(c);
|
| 852 |
seen.add(k);
|
| 853 |
+
if (added.length >= limit) break;
|
| 854 |
+
}
|
| 855 |
+
if (added.length) {
|
| 856 |
+
// Prefer dedicated Imudex-family matches for cabinet-hardware queries.
|
| 857 |
+
const fam = /khoa|khoá|taynam|banle|ray|thungrac|giagiavi|giatri|kegia|kexi|kedao|kechen|kebat|kexoong|chot|moc|lock|smart|nangha|nang hạ/i.test(qNorm)
|
| 858 |
+
|| /khoa|khóa|kệ|tay nắm|bản lề|thùng rác|giá gia vị|chốt|móc|ray|nâng hạ|ổ khóa|khóa điện tử/i.test(q);
|
| 859 |
+
// When the query is clearly cabinet hardware, Imudex (specific) should
|
| 860 |
+
// come before generic Malloca/Grob matches.
|
| 861 |
+
const familia = fam || cat.length >= Math.min(limit, 3);
|
| 862 |
+
const final = familia ? [...added, ...ranked] : [...ranked, ...added];
|
| 863 |
+
return final.slice(0, limit).map((p: any, i: number) => ({ ...p, _idx: i }));
|
| 864 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
}
|
| 866 |
return ranked.slice(0, limit);
|
| 867 |
}
|