summaryrefslogtreecommitdiff
path: root/src/pages/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/api')
-rw-r--r--src/pages/api/shop/search.js51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index e14b0ca2..8c9782cb 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) {
@@ -73,7 +72,7 @@ export default async function handler(req, res) {
const formattedQuery = `(${newQ
.split(' ')
- .map((term) => (term.length < 2 ? term : `${term}*`)) // Tambahkan '*' hanya jika panjang kata >= 2
+ .map((term) => (term.length < 2 ? term : `${term}*`))
.join(' ')})`;
const mm =
@@ -90,7 +89,7 @@ export default async function handler(req, res) {
];
if (orderBy === 'stock') {
- filterQueries.push('stock_total_f:{0 TO *}');
+ filterQueries.push('stock_total_f:[1 TO *]');
}
if (fq && source != 'similar' && typeof fq != 'string') {
@@ -112,8 +111,9 @@ export default async function handler(req, res) {
let offset = (page - 1) * limit;
let parameter = [
- 'facet.field=manufacture_name_s',
- 'facet.field=category_name',
+ // === Facet disjunctive: exclude filter brand/cat saat hitung facet ===
+ 'facet.field={!ex=brand}manufacture_name_s',
+ 'facet.field={!ex=cat}category_name',
'facet=true',
'indent=true',
`facet.query=${escapeSolrQuery(q)}`,
@@ -142,25 +142,29 @@ 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 *}`);
+ if (stock) parameter.push(`fq=stock_total_f:(1 TO *)`);
// Single fq in url params
if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`);
@@ -169,6 +173,7 @@ export default async function handler(req, res) {
parameter = parameter.concat(
fq.map((val) => `fq=${encodeURIComponent(val)}`)
);
+
let result = await axios(
process.env.SOLR_HOST + '/solr/product/select?' + parameter.join('&')
);