summaryrefslogtreecommitdiff
path: root/src/pages/api
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-09-02 16:24:39 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-09-02 16:24:39 +0700
commit31ce275bf6013bf6ee2e3a2d7f22d2547cab0b70 (patch)
tree56f6b46bed43ff47cad21c136a207a9a3df9dc28 /src/pages/api
parent631f103bf56f8c8858e0a16aabe0e8e25751c97b (diff)
parent932b92af3f3a1a0a62bef60d647c00e1be483265 (diff)
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into regenerate-midtrans
Diffstat (limited to 'src/pages/api')
-rw-r--r--src/pages/api/shop/search.js63
1 files changed, 24 insertions, 39 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index 3d258a97..1760be70 100644
--- a/src/pages/api/shop/search.js
+++ b/src/pages/api/shop/search.js
@@ -19,7 +19,6 @@ export default async function handler(req, res) {
source = '',
} = req.query;
-
let { stock = '' } = req.query;
let paramOrderBy = '';
switch (orderBy) {
@@ -49,25 +48,6 @@ export default async function handler(req, res) {
break;
}
- // let suggestWord = null;
- // let keywords = q;
- // let checkQ = null;
-
- // if (q != '*') {
- // checkQ = q.trim().split(/[\s\+\-\!\(\)\{\}\[\]\^"~\*\?:\\\/]+/);
- // if (checkQ.length > 1) {
- // const dataSearchSuggest = await axios(
- // `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/suggest?q=${checkQ[1]}`
- // );
- // suggestWord = dataSearchSuggest.data.suggestions[0];
- // }
- // if (suggestWord && suggestWord?.term.split(' ').length <= 1) {
- // keywords = `"${escapeSolrQuery(checkQ[0] + ' ' + suggestWord?.term)}"`;
- // }
- // }
-
- // let newQ = keywords;
-
let checkQ = q.trim().split(/[\s\+\-\!\(\)\{\}\[\]\^"~\*\?:\\\/]+/);
let newQ = escapeSolrQuery(q);
@@ -113,8 +93,9 @@ export default async function handler(req, res) {
let offset = (page - 1) * limit;
let parameter = [
- 'facet.field=manufacture_name_s',
- 'facet.field=category_name',
+ // === Disjunctive facets: exclude brand & category filters saat hitung facet ===
+ 'facet.field={!ex=brand}manufacture_name_s',
+ 'facet.field={!ex=cat}category_name',
'facet=true',
'indent=true',
`facet.query=${escapeSolrQuery(q)}`,
@@ -143,23 +124,27 @@ export default async function handler(req, res) {
if (auth.feature.onlyReadyStock) stock = true;
}
- if (brand)
- parameter.push(
- `fq=${brand
- .split(',')
- .map(
- (manufacturer) =>
- `manufacture_name:"${encodeURIComponent(manufacturer)}"`
- )
- .join(' OR ')}`
- );
- if (category)
- parameter.push(
- `fq=${category
- .split(',')
- .map((cat) => `category_name:"${encodeURIComponent(cat)}"`)
- .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) {
+ // 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 *}`);