summaryrefslogtreecommitdiff
path: root/src/pages/api/shop/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/api/shop/search.js')
-rw-r--r--src/pages/api/shop/search.js31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index 1f0ff504..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,12 +93,24 @@ export default async function handler(req, res) {
'price_tier1_v2_f:[1 TO *]',
];
- if (fq && source != 'similar') {
+
+ 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',
@@ -102,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)}`,
@@ -153,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(