diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-11-18 11:35:58 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-11-18 11:35:58 +0700 |
| commit | fb58a58715a7f5530a60479487457e5e0a1a41ec (patch) | |
| tree | 733f0332f127a4d6bc931330ec1cd103968dbb7d /src/pages/api/shop/search.js | |
| parent | 0d4278bd482d2ec2563b29cb3597eb8c7227a2d7 (diff) | |
| parent | bde516b6b39cccfe8ac3248cd7f85592e6298d7a (diff) | |
Merge branch 'new-release' into feature/integrasi_biteship
Diffstat (limited to 'src/pages/api/shop/search.js')
| -rw-r--r-- | src/pages/api/shop/search.js | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index ace281f7..65927bbc 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -19,6 +19,10 @@ export default async function handler(req, res) { source = '', } = req.query; + + + console.log('fq new', fq); + let { stock = '' } = req.query; let paramOrderBy = ''; @@ -73,8 +77,9 @@ export default async function handler(req, res) { const formattedQuery = `(${newQ .split(' ') - .map((term) => `${term}*`) + .map((term) => (term.length < 2 ? term : `${term}*`)) // Tambahkan '*' hanya jika panjang kata >= 2 .join(' ')})`; + const mm = checkQ.length > 2 ? checkQ.length > 5 @@ -88,11 +93,24 @@ export default async function handler(req, res) { 'price_tier1_v2_f:[1 TO *]', ]; - if (fq && source != 'similar') { - filterQueries.push(fq); + + if (fq && source != 'similar' && typeof fq != 'string') { + // filterQueries.push(fq); + fq.push(...filterQueries); } const fq_ = filterQueries.join(' AND '); + let keywords = newQ; + if (source === 'similar' || checkQ.length < 3) { + if (checkQ.length < 2 || checkQ[1].length < 2) { + keywords = newQ ; + } else { + keywords = newQ + '*'; + } + } else { + keywords = formattedQuery; + } + let offset = (page - 1) * limit; let parameter = [ 'facet.field=manufacture_name_s', @@ -101,13 +119,7 @@ export default async function handler(req, res) { 'indent=true', `facet.query=${escapeSolrQuery(q)}`, `q.op=OR`, - `q=${ - source == 'similar' || checkQ.length < 3 - ? checkQ.length < 2 - ? newQ - : newQ + '*' - : formattedQuery - }`, + `q=${keywords}`, `defType=edismax`, 'qf=name_s description_clean_t category_name manufacture_name_s variants_code_t variants_name_t category_id_ids default_code_s manufacture_id_i category_id_i ', `start=${parseInt(offset)}`, @@ -152,7 +164,7 @@ export default async function handler(req, res) { if (stock) parameter.push(`fq=stock_total_f:{1 TO *}`); // Single fq in url params - // if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); + if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); // Multi fq in url params if (Array.isArray(fq)) parameter = parameter.concat( |
