bep40 commited on
Commit
f67b40b
·
verified ·
1 Parent(s): b53f03b

v7: lead Catalogue AI matches for cabinet-hardware queries (khóa/tay nắm/thùng rác/kệ...)

Browse files
Files changed (1) hide show
  1. index.ts +14 -10
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 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 || "")));
@@ -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 (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
  }
 
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
  }