From c69b71c16ff7cc7a347394710d069ef711db08bb Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Fri, 15 Nov 2024 14:55:36 +0700 Subject: cr logic generate keywords --- src/pages/api/shop/search.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/pages/api') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 1f0ff504..a789b469 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -73,8 +73,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 @@ -94,6 +95,17 @@ export default async function handler(req, res) { } 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', @@ -102,13 +114,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)}`, -- cgit v1.2.3 From c3ff9d2b35efd260bf7bfa7cc924ed05b8f9418f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 18 Nov 2024 08:29:50 +0700 Subject: fix bug --- src/pages/api/shop/search.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pages/api') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 1f0ff504..4b59f741 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -89,8 +89,8 @@ export default async function handler(req, res) { ]; if (fq && source != 'similar') { - // filterQueries.push(fq); - fq.push(...filterQueries); + filterQueries.push(fq); + // fq.push(...filterQueries); } const fq_ = filterQueries.join(' AND '); -- cgit v1.2.3 From 986e2e47037c6d99b184ec0edc1fbf591f0582a8 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 18 Nov 2024 10:51:34 +0700 Subject: bug fix search category dinanmis --- src/pages/api/shop/search.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/pages/api') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 4fc2ab2b..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 = ''; @@ -89,9 +93,10 @@ export default async function handler(req, res) { 'price_tier1_v2_f:[1 TO *]', ]; - if (fq && source != 'similar') { - filterQueries.push(fq); - // fq.push(...filterQueries); + + if (fq && source != 'similar' && typeof fq != 'string') { + // filterQueries.push(fq); + fq.push(...filterQueries); } const fq_ = filterQueries.join(' AND '); @@ -159,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( -- cgit v1.2.3