diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2024-09-12 03:19:01 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2024-09-12 03:19:01 +0000 |
| commit | 375365d46144e6f20bf7d4ffee1f52e6400cf214 (patch) | |
| tree | 7c5ebb2547716782301fce7d27d2cf478755d2b8 | |
| parent | 46faf7e7ba398a4137e93559b2efa5abf3df9663 (diff) | |
| parent | 3918b401286243a6ceb376d267b802b87f1b1a2f (diff) | |
Merged in CR/search_enggine (pull request #308)
CR/search enggine
| -rw-r--r-- | src-migrate/libs/odooApi.ts | 2 | ||||
| -rw-r--r-- | src-migrate/services/product.ts | 3 | ||||
| -rw-r--r-- | src/core/api/odooApi.js | 2 | ||||
| -rw-r--r-- | src/lib/product/components/ProductSearch.jsx | 4 | ||||
| -rw-r--r-- | src/pages/api/shop/search.js | 57 | ||||
| -rw-r--r-- | src/pages/index.jsx | 8 |
6 files changed, 57 insertions, 19 deletions
diff --git a/src-migrate/libs/odooApi.ts b/src-migrate/libs/odooApi.ts index 9482542b..cf839fd9 100644 --- a/src-migrate/libs/odooApi.ts +++ b/src-migrate/libs/odooApi.ts @@ -73,7 +73,7 @@ const odooApi = async ( return authResponse.result || null; } catch (error) { - console.log(error); + // console.log(error); return null; } }; diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts index a6abba47..77b645f0 100644 --- a/src-migrate/services/product.ts +++ b/src-migrate/services/product.ts @@ -44,7 +44,8 @@ export const getProductSimilar = async ({ `q=${name}`, 'page=1', 'operation=OR', - 'priceFrom=1', + // 'priceFrom=1', + `source=similar`, ]; if (except?.productId) query.push(`fq=-product_id_i:${except.productId}`); diff --git a/src/core/api/odooApi.js b/src/core/api/odooApi.js index 3349ff4b..504d097a 100644 --- a/src/core/api/odooApi.js +++ b/src/core/api/odooApi.js @@ -64,7 +64,7 @@ const odooApi = async (method, url, data = {}, headers = {}) => { } return camelcaseObjectDeep(res.data.result) || []; } catch (error) { - console.log(error); + // console.log(error); } }; diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index ab55cae0..1edc31c9 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -381,6 +381,8 @@ const ProductSearch = ({ }; const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock'; + + console.log('is spelling', spellings); return ( <> <MobileView> @@ -574,7 +576,7 @@ const ProductSearch = ({ /> <div className='flex justify-between items-center mb-5'> <div className='leading-6 text-gray_r-11'> - {!spellings ? ( + {spellings?.length < 1 || !spellings ? ( <> Menampilkan {pageCount > 1 ? ( diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 6f98efcb..6269d3ed 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -1,6 +1,8 @@ import { productMappingSolr } from '@/utils/solrMapping'; import axios from 'axios'; import camelcaseObjectDeep from 'camelcase-object-deep'; +import searchSuggestApi from '@/core/api/searchSuggestApi'; +import { ECDH } from 'crypto'; export default async function handler(req, res) { const { @@ -14,6 +16,7 @@ export default async function handler(req, res) { operation = 'AND', fq = '', limit = 30, + source = '', } = req.query; let { stock = '' } = req.query; @@ -42,10 +45,40 @@ export default async function handler(req, res) { paramOrderBy += ''; break; } - + + // let suggestWord = null; + // let keywords = q; + // let checkQ = null; + + // if (q != '*') { + // checkQ = q.trim().split(/[\s\+\-\!\(\)\{\}\[\]\^"~\*\?:\\\/]+/); + // if (checkQ.length > 1) { + // const dataSearchSuggest = await axios( + // `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/suggest?q=${checkQ[1]}` + // ); + // suggestWord = dataSearchSuggest.data.suggestions[0]; + // } + // if (suggestWord && suggestWord?.term.split(' ').length <= 1) { + // keywords = `"${escapeSolrQuery(checkQ[0] + ' ' + suggestWord?.term)}"`; + // } + // } + + // let newQ = keywords; + let checkQ = q.trim().split(/[\s\+\-\!\(\)\{\}\[\]\^"~\*\?:\\\/]+/); - let newQ = checkQ.length > 1 ? escapeSolrQuery(q) + '*' : escapeSolrQuery(q); + let newQ = escapeSolrQuery(q); + + const formattedQuery = `(${newQ.split(' ').map(term => `${term}*`).join(' ') })`; + const mm = checkQ.length > 2 ? checkQ.length > 5 ? '55%' : '85%' : `${checkQ.length}`; + + const filterQueries = [ + '-publish_b:false', + 'product_rating_f:[8 TO *]', + 'price_tier1_v2_f:[1 TO *]' + ]; + const fq_ = filterQueries.join('AND '); + let offset = (page - 1) * limit; let parameter = [ 'facet.field=manufacture_name_s', @@ -53,13 +86,15 @@ export default async function handler(req, res) { 'facet=true', 'indent=true', `facet.query=${escapeSolrQuery(q)}`, - `q.op=${operation}`, - `q=${newQ}`, - 'qf=name_s', + `q.op=OR`, + `q=${source == 'similar' || checkQ.length < 3 ? checkQ.length < 2 ? newQ : newQ + '*' : formattedQuery }`, + `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', `start=${parseInt(offset)}`, `rows=${limit}`, `sort=${paramOrderBy}`, - `fq=-publish_b:false, product_rating_f:[8 TO *], price_tier1_v2_f:[1 TO *]`, + `fq=${encodeURIComponent(fq_)}`, + `mm=${encodeURIComponent(mm)}`, ]; if (priceFrom > 0 || priceTo > 0) { @@ -97,14 +132,15 @@ 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=${fq}`); + if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); // Multi fq in url params if (Array.isArray(fq)) - parameter = parameter.concat(fq.map((val) => `fq=${val}`)); - + parameter = parameter.concat(fq.map((val) => `fq=${encodeURIComponent(val)}`)); + let result = await axios( process.env.SOLR_HOST + '/solr/product/select?' + parameter.join('&') ); + try { result.data.response.products = productMappingSolr( result.data.response.docs, @@ -126,7 +162,7 @@ export default async function handler(req, res) { const escapeSolrQuery = (query) => { if (query == '*') return query; - + query = query.replace(/-/g, ' '); const specialChars = /([\+\!\(\)\{\}\[\]\^"~\*\?:\\\/])/g; @@ -141,7 +177,6 @@ const escapeSolrQuery = (query) => { return escapedWords.join(' '); }; - /*const productResponseMap = (products, pricelist) => { return products.map((product) => { let price = product.price_tier1_v2_f || 0 diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 613950a6..0e87205e 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -10,7 +10,7 @@ import { FlashSaleSkeleton } from '@/lib/flashSale/skeleton/FlashSaleSkeleton'; import PreferredBrandSkeleton from '@/lib/home/components/Skeleton/PreferredBrandSkeleton'; import BannerPromoSkeleton from '@/lib/home/components/Skeleton/BannerPromoSkeleton'; import PromotinProgram from '@/lib/promotinProgram/components/HomePage'; -import PagePopupIformation from '~/modules/popup-information'; +import PagePopupIformation from '~/modules/popup-information'; // need change to dynamic and ssr : false import CategoryPilihan from '../lib/home/components/CategoryPilihan'; import odooApi from '@/core/api/odooApi'; import { getAuth } from '~/libs/auth'; @@ -56,7 +56,7 @@ const ProgramPromotion = dynamic(() => const BannerSection = dynamic(() => import('@/lib/home/components/BannerSection') -); +); const CategoryHomeId = dynamic(() => import('@/lib/home/components/CategoryHomeId') ); @@ -71,8 +71,8 @@ import('@/lib/home/components/CategoryDynamicMobile') const CustomerReviews = dynamic(() => import('@/lib/review/components/CustomerReviews') -); -const ServiceList = dynamic(() => import('@/lib/home/components/ServiceList')); +); // need to ssr:false +const ServiceList = dynamic(() => import('@/lib/home/components/ServiceList')); // need to ssr: false |
