Closed SAYEED05 closed 3 years ago
hello there
one simple solution can be replacing ( with /( in the search term in this line:
using this code:
$regex: req.query.keyword.replaceAll('(','/(').replaceAll(')','/)'),
sample code:
const s = "shirt (white) (green)"; console.log(s.replaceAll('(','/(').replaceAll(')','/)')); result:
"shirt /(white/) /(green/)"
not working.Like i said before the problem is not when i try to search the words with brackets, its when i try to search words inside and outside brackets. for example if there is a product named playstation (white) when i search playstation or (white) it works fine.But when i search playstation (white) it returns no products
what I suggest is to get words from the search term and use logical OR to search for them. like: playstation (white) => [playstation, white] => filter by name:playstation or name:white
when trying to search, if there is () after a word in the search term the result is empty.
for example if there is a product with name 'playstation (white)' ,if i search 'playstation' or 'white' or even '(white)' the result shows.but if i search 'playstation (white)' the result is empty.
i think the bug is due to regex because when i tried to type for example: 'playstation ('
this error occurs Regular expression is invalid: missing ) .but i don't know how to resolve it.
when i tried to search 'playstation /(white/),
lets say there are 3 products : playstation (white),playstation (black),xbox
it shows playstation (white) and playstation (black)
i tried it with this repo also.