diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-05 10:50:31 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-05 10:50:31 +0700 |
| commit | 9ca4e764383ffc3800fbe899dd7e07c297c51e75 (patch) | |
| tree | dcdbae47ccc58d145802a5fb127fcbfc45176a12 /src/pages/searchkey | |
| parent | c10b1479d9a134700f10c3f8c734daf5042626c5 (diff) | |
<Miqdad> fix query
Diffstat (limited to 'src/pages/searchkey')
| -rw-r--r-- | src/pages/searchkey/[slug].jsx | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/src/pages/searchkey/[slug].jsx b/src/pages/searchkey/[slug].jsx index f09520f4..9cf1df05 100644 --- a/src/pages/searchkey/[slug].jsx +++ b/src/pages/searchkey/[slug].jsx @@ -47,26 +47,41 @@ export default function KeywordPage() { } }, [router.isReady]); - // Jika Solr index ditemukan, siapkan parameter pencarian useEffect(() => { if (result) { - const fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`; - const q = keyword || '*:*'; // keyword dari URL + let fqParts = []; + + if (result.category_id_i) { + fqParts.push(`category_parent_ids:${result.category_id_i}`); + } + + if (result.brand_id_i) { + fqParts.push(`manufacture_id_i:${result.brand_id_i}`); + } + + const fq = fqParts.join(' AND '); + const q = keyword || '*:*'; + console.log('SOLR QUERY:', { q, fq }); - setQuery({ fq, q }); + + setQuery({ + fq, + q, + from: 'searchkey', + }); } }, [result, keyword]); - if (!result) { - return ( - <BasicLayout> - <Seo title='Keyword tidak ditemukan' /> - <div className='container py-5'> - <h2>Produk tidak ditemukan berdasarkan keyword</h2> - </div> - </BasicLayout> - ); - } + // if (!result) { + // return ( + // <BasicLayout> + // <Seo title='Keyword tidak ditemukan' /> + // <div className='container py-5'> + // <h2>Produk tidak ditemukan berdasarkan keyword</h2> + // </div> + // </BasicLayout> + // ); + // } return ( <BasicLayout> @@ -83,7 +98,12 @@ export default function KeywordPage() { router.asPath.split('?')[0] }`} /> - {query && <ProductSearch query={query} prefixUrl={`${router.asPath}`} />} + {query && ( + <ProductSearch + query={{ ...query, from: 'searchkey' }} + prefixUrl={router.asPath} + /> + )} </BasicLayout> ); } |
