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();