Spaces:
Running
Running
v6: boost Imudex-family CATAI results to top in server search (tay nắm/thùng rác/kệ... now lead with Imudex)
Browse files
index.ts
CHANGED
|
@@ -837,20 +837,29 @@ async function serverSearchProducts(q: string, limit: number): Promise<any[]> {
|
|
| 837 |
}
|
| 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 |
-
//
|
| 841 |
-
//
|
|
|
|
|
|
|
| 842 |
const cat = await serverSearchCatai(q, limit);
|
| 843 |
-
if (
|
| 844 |
const seen = new Set(ranked.map(r => String(r.sku || "") + String(r.name || "")));
|
|
|
|
| 845 |
for (const c of cat) {
|
| 846 |
const k = String(c.sku || "") + String(c.name || "");
|
| 847 |
if (seen.has(k)) continue;
|
| 848 |
-
|
| 849 |
seen.add(k);
|
| 850 |
-
if (ranked.length >= limit) break;
|
| 851 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
}
|
| 853 |
-
return ranked;
|
| 854 |
}
|
| 855 |
// Derive a coarse product family from the product NAME for diverse combos.
|
| 856 |
function serverItemFamily(p: any): string {
|
|
|
|
| 837 |
}
|
| 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 also surface
|
| 842 |
+
// Imudex items. Merge CATAI hits, then interleave strong CATAI matches to the
|
| 843 |
+
// top when the query looks like an Imudex-family keyword.
|
| 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 || "")));
|
| 847 |
+
const added: any[] = [];
|
| 848 |
for (const c of cat) {
|
| 849 |
const k = String(c.sku || "") + String(c.name || "");
|
| 850 |
if (seen.has(k)) continue;
|
| 851 |
+
added.push(c);
|
| 852 |
seen.add(k);
|
| 853 |
+
if (ranked.length + added.length >= limit * 2) break;
|
| 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 |
}
|
| 864 |
// Derive a coarse product family from the product NAME for diverse combos.
|
| 865 |
function serverItemFamily(p: any): string {
|