summaryrefslogtreecommitdiff
path: root/src/pages/api/shop/searchkey.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/api/shop/searchkey.js')
-rw-r--r--src/pages/api/shop/searchkey.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js
new file mode 100644
index 00000000..f5546a36
--- /dev/null
+++ b/src/pages/api/shop/searchkey.js
@@ -0,0 +1,43 @@
+import axios from 'axios';
+
+export default async function handler(req, res) {
+ const { url = '', page = 1, limit = 30, all } = req.query;
+
+ let q = '*:*';
+
+ // ✅ kalau BUKAN sitemap
+ if (!all) {
+ const cleanUrl = url.trim();
+ if (!cleanUrl) {
+ return res.status(400).json({ error: 'Missing url param' });
+ }
+ q = `keywords_s:"${cleanUrl}"`;
+ }
+
+ const offset = (page - 1) * limit;
+
+ const params = [
+ `q.op=AND`,
+ `q=${q}`,
+ `indent=true`,
+ `rows=${limit}`,
+ `start=${offset}`,
+ ];
+
+ try {
+ const result = await axios.post(
+ `${process.env.SOLR_HOST}/solr/searchkey/select`,
+ params.join('&'),
+ {
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ }
+ );
+
+ res.status(200).json(result.data);
+ } catch (error) {
+ console.error(error?.response?.data || error);
+ res.status(500).json({ error: 'Internal Server Error' });
+ }
+}