From f6b1aea824192572b241f94157ab3731dec6a4ea Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 14 Oct 2025 09:29:14 +0700 Subject: fix brand solr --- src/pages/api/shop/search.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 6bf10672..8c9782cb 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -142,30 +142,29 @@ export default async function handler(req, res) { if (auth.feature.onlyReadyStock) stock = true; } - if (brand) - parameter.push( - // tag filter brand - `fq=${encodeURIComponent( - `{!tag=brand}manufacture_name_s:(${brand - .split(',') - .map((manufacturer) => `"${manufacturer.replace(/"/g, '\\"')}"`) - .join(' OR ')})` - )}` - ); + if (brand) { + // bentuk ekspresi sama seperti versi kamu, tapi dibungkus tag brand + const brandExpr = brand + .split(',') + .map( + (manufacturer) => + `manufacture_name:"${encodeURIComponent(manufacturer)}"` + ) + .join(' OR '); + parameter.push(`fq={!tag=brand}(${brandExpr})`); + } - if (category) - parameter.push( - // tag filter category - `fq=${encodeURIComponent( - `{!tag=cat}category_name:(${category - .split(',') - .map((cat) => `"${cat.replace(/"/g, '\\"')}"`) - .join(' OR ')})` - )}` - ); + if (category) { + // sama: tag kategori + const catExpr = category + .split(',') + .map((cat) => `category_name:"${encodeURIComponent(cat)}"`) + .join(' OR '); + parameter.push(`fq={!tag=cat}(${catExpr})`); + } // if (category) parameter.push(`fq=category_name:${capitalizeFirstLetter(category.replace(/,/g, ' OR '))}`) - if (stock) parameter.push(`fq=stock_total_f:[1 TO *]`); + if (stock) parameter.push(`fq=stock_total_f:(1 TO *)`); // Single fq in url params if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); -- cgit v1.2.3