From 95b27ddb0604fbb4fae130f2d80e5ee2aec6d0fc Mon Sep 17 00:00:00 2001 From: Mqdd Date: Thu, 11 Dec 2025 09:00:03 +0700 Subject: fix --- src/pages/api/shop/searchkey.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/pages/api/shop/searchkey.js (limited to 'src/pages/api/shop/searchkey.js') diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js new file mode 100644 index 00000000..e8b535e7 --- /dev/null +++ b/src/pages/api/shop/searchkey.js @@ -0,0 +1,31 @@ +import axios from 'axios'; + +export default async function handler(req, res) { + const { url = '', page = 1, limit = 30 } = req.query; + + let offset = (page - 1) * limit; + + const params = [ + `q.op=AND`, + `q=keywords_s:"${url}"`, + `indent=true`, + `rows=${limit}`, + `start=${offset}`, + ]; + + try { + // let result = await axios( + // process.env.SOLR_HOST + `/solr/searchkey/select?` + params.join('&') + // ); + let result = await axios.post( + process.env.SOLR_HOST + `/solr/searchkey/select`, + params.join('&'), + { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } + ); + + console.log(result.data); + res.status(200).json(result.data); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } +} -- cgit v1.2.3 From 7cdb4cef31577818682b63ccbe01b53dd08a9207 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Thu, 11 Dec 2025 09:31:51 +0700 Subject: sitemap done --- src/pages/api/shop/searchkey.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/pages/api/shop/searchkey.js') diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js index e8b535e7..2735e72c 100644 --- a/src/pages/api/shop/searchkey.js +++ b/src/pages/api/shop/searchkey.js @@ -3,11 +3,18 @@ import axios from 'axios'; export default async function handler(req, res) { const { url = '', page = 1, limit = 30 } = req.query; + let q = '*:*'; + + if (!req.query.all) { + const url = (req.query.q || '').trim(); + q = `keywords_s:"${url}"`; + } let offset = (page - 1) * limit; const params = [ `q.op=AND`, - `q=keywords_s:"${url}"`, + // `q=keywords_s:"${url}"`, + `q=${q}`, `indent=true`, `rows=${limit}`, `start=${offset}`, -- cgit v1.2.3 From 5808e82529933aee7c63ede955f64028fd1f38ee Mon Sep 17 00:00:00 2001 From: Mqdd Date: Tue, 16 Dec 2025 14:34:47 +0700 Subject: fix bug & add category --- src/pages/api/shop/searchkey.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/pages/api/shop/searchkey.js') diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js index 2735e72c..f5546a36 100644 --- a/src/pages/api/shop/searchkey.js +++ b/src/pages/api/shop/searchkey.js @@ -1,19 +1,23 @@ import axios from 'axios'; export default async function handler(req, res) { - const { url = '', page = 1, limit = 30 } = req.query; + const { url = '', page = 1, limit = 30, all } = req.query; let q = '*:*'; - if (!req.query.all) { - const url = (req.query.q || '').trim(); - q = `keywords_s:"${url}"`; + // ✅ kalau BUKAN sitemap + if (!all) { + const cleanUrl = url.trim(); + if (!cleanUrl) { + return res.status(400).json({ error: 'Missing url param' }); + } + q = `keywords_s:"${cleanUrl}"`; } - let offset = (page - 1) * limit; + + const offset = (page - 1) * limit; const params = [ `q.op=AND`, - // `q=keywords_s:"${url}"`, `q=${q}`, `indent=true`, `rows=${limit}`, @@ -21,18 +25,19 @@ export default async function handler(req, res) { ]; try { - // let result = await axios( - // process.env.SOLR_HOST + `/solr/searchkey/select?` + params.join('&') - // ); - let result = await axios.post( - process.env.SOLR_HOST + `/solr/searchkey/select`, + const result = await axios.post( + `${process.env.SOLR_HOST}/solr/searchkey/select`, params.join('&'), - { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + } ); - console.log(result.data); res.status(200).json(result.data); } catch (error) { + console.error(error?.response?.data || error); res.status(500).json({ error: 'Internal Server Error' }); } } -- cgit v1.2.3