I have an array of objects that I am filtering through based on a query. If the query matches a title inside the array of objects I return it.
const arr = [{ title: 'Xbox one controller' }];
const filterResults = arr.filter((item) =>
item.title.toLowerCase().includes(req.query.q.toLowerCase())
);
res.send(filterResults);
These words if I just search on a word like "xbox", however, if I search "xbox controller" it returns nothing.
I was thinking of splitting req.query like this: const reqy = req.query.q.split(' ')
and using those as keywords although I don't really know where to start. Another potential problem with my "solution" is that if a query looks like "Controller for Xbox One" will the result even show up?
My problem is making the filter function accept multiple "keywords" derived from the user query.