Spaces:
Running
Running
Nâng cấp tìm kiếm: search qua mô tả chi tiết, thông số kỹ thuật, tính năng, tóm tắt sản phẩm (pre-built index)
Browse files- index.html +9 -2
index.html
CHANGED
|
@@ -481,7 +481,14 @@ const PRICES=[
|
|
| 481 |
{l:'15-30 triệu',min:15e6,max:3e7},{l:'30-50 triệu',min:3e7,max:5e7},{l:'Trên 50 triệu',min:5e7,max:1e15}
|
| 482 |
];
|
| 483 |
|
| 484 |
-
fetch('products.json').then(r=>r.json()).then(d=>{D=d.map(p=>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
|
| 486 |
function init(){buildCats();buildPrices();render()}
|
| 487 |
|
|
@@ -500,7 +507,7 @@ document.getElementById('pr').innerHTML=h;document.getElementById('prm').innerHT
|
|
| 500 |
function getF(){
|
| 501 |
let r=D;
|
| 502 |
if(S.cat!=='all')r=r.filter(p=>p.catSlug===S.cat);
|
| 503 |
-
if(S.q){let q=S.q.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'');r=r.filter(p=>
|
| 504 |
if(S.pmin>0||S.pmax<1e15)r=r.filter(p=>p.priceNum>=S.pmin&&p.priceNum<=S.pmax);
|
| 505 |
if(S.sort==='pa')r.sort((a,b)=>a.priceNum-b.priceNum);
|
| 506 |
else if(S.sort==='pd')r.sort((a,b)=>b.priceNum-a.priceNum);
|
|
|
|
| 481 |
{l:'15-30 triệu',min:15e6,max:3e7},{l:'30-50 triệu',min:3e7,max:5e7},{l:'Trên 50 triệu',min:5e7,max:1e15}
|
| 482 |
];
|
| 483 |
|
| 484 |
+
fetch('products.json').then(r=>r.json()).then(d=>{D=d.map(p=>{let o={name:p.n,link:p.l,image:p.i,price:p.p,priceNum:p.pn,cat:p.c,catSlug:p.cs,catIcon:p.ci,images:p.imgs||[],summary:p.sum||'',desc:p.desc||'',specs:p.specs||{},feats:p.feats||[],sku:p.sku||'',video:p.vid||'',model:p.mod||''};o._idx=buildSearchIndex(o);return o});init()});
|
| 485 |
+
|
| 486 |
+
function buildSearchIndex(p){
|
| 487 |
+
let parts=[p.name,p.cat,p.sku,p.model,'malloca',p.summary,p.desc,p.price];
|
| 488 |
+
if(p.feats&&p.feats.length)parts.push(p.feats.join(' '));
|
| 489 |
+
if(p.specs){Object.entries(p.specs).forEach(([k,v])=>{parts.push(k);parts.push(v)})}
|
| 490 |
+
return parts.join(' ').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'');
|
| 491 |
+
}
|
| 492 |
|
| 493 |
function init(){buildCats();buildPrices();render()}
|
| 494 |
|
|
|
|
| 507 |
function getF(){
|
| 508 |
let r=D;
|
| 509 |
if(S.cat!=='all')r=r.filter(p=>p.catSlug===S.cat);
|
| 510 |
+
if(S.q){let q=S.q.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'');r=r.filter(p=>p._idx.includes(q))}
|
| 511 |
if(S.pmin>0||S.pmax<1e15)r=r.filter(p=>p.priceNum>=S.pmin&&p.priceNum<=S.pmax);
|
| 512 |
if(S.sort==='pa')r.sort((a,b)=>a.priceNum-b.priceNum);
|
| 513 |
else if(S.sort==='pd')r.sort((a,b)=>b.priceNum-a.priceNum);
|