From f4f29e9a0b4830a197215db8d2652df7de6f9291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B5=ED=9D=AC=20=EA=B9=80?= Date: Thu, 23 Jan 2025 03:41:56 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=80=EC=83=89=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/search.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controllers/search.js b/src/controllers/search.js index 9d95f43..4a4c566 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -5,6 +5,7 @@ const Brand = require('../models/Brand'); const SubCategory = require('../models/SubCategory'); const Search = async (req, res) => { + try { const { query, shop, subCategory, category } = req.body; const currenctShop = shop ? await Shop.findById(shop).select(['_id']) : ''; @@ -17,7 +18,11 @@ const Search = async (req, res) => { const products = await Products.aggregate([ { $match: { - name: { $regex: query || '', $options: 'i' }, + $or: [ + { name: { $regex: query || '', $options: 'i' } }, + { metaTitle: { $regex: query || '', $options: 'i' } }, + { description: { $regex: query || '', $options: 'i' } } + ], ...(currenctShop && { shop: currenctShop._id, }), @@ -56,6 +61,8 @@ const Search = async (req, res) => { slug: 1, _id: 1, category: 1, // Including the category field with only the title + metaTitle: 1, + description: 1, }, }, @@ -72,6 +79,8 @@ const Search = async (req, res) => { return res.status(400).json({ success: false, message: error.message }); } }; + + const getFilters = async (req, res) => { try { await SubCategory.findOne();