diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-08-30 06:56:09 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-08-30 06:56:09 +0000 |
| commit | 58e75871483917ac842c7d95dfbf0bdd65ecaafd (patch) | |
| tree | a7deedd39dabac00eeb2e8b0ccc2ad7554568162 /src/pages/api/shop | |
| parent | 39c537b0036a08f2d54ba425bb2bddfa4164d924 (diff) | |
| parent | 7735e705142e9a56f37c90b09ea5e6ba80d2bfa3 (diff) | |
Merged in filter-search (pull request #452)
<Miqdad> Done apply filter without button
Diffstat (limited to 'src/pages/api/shop')
| -rw-r--r-- | src/pages/api/shop/search.js | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 3d258a97..81cc22c5 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,8 +89,7 @@ export default async function handler(req, res) { ]; if (orderBy === 'stock') { - filterQueries.push('stock_total_f:{1 TO *}&sort=stock_total_f desc'); - // filterQueries.push(`stock_total_f DESC`) + filterQueries.push('stock_total_f:[1 TO *]'); } if (fq && source != 'similar' && typeof fq != 'string') { @@ -113,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)}`, @@ -145,23 +144,28 @@ export default async function handler(req, res) { if (brand) parameter.push( - `fq=${brand - .split(',') - .map( - (manufacturer) => - `manufacture_name:"${encodeURIComponent(manufacturer)}"` - ) - .join(' OR ')}` + // tag filter brand + `fq=${encodeURIComponent( + `{!tag=brand}manufacture_name_s:(${brand + .split(',') + .map((manufacturer) => `"${manufacturer.replace(/"/g, '\\"')}"`) + .join(' OR ')})` + )}` ); + if (category) parameter.push( - `fq=${category - .split(',') - .map((cat) => `category_name:"${encodeURIComponent(cat)}"`) - .join(' OR ')}` + // tag filter category + `fq=${encodeURIComponent( + `{!tag=cat}category_name:(${category + .split(',') + .map((cat) => `"${cat.replace(/"/g, '\\"')}"`) + .join(' OR ')})` + )}` ); + // 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)}`); @@ -170,6 +174,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('&') ); |
