From 08960ff51410a1994fb9879be865d04cb87edcd1 Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Sun, 27 Dec 2020 12:19:09 +0100 Subject: [PATCH] Autocomplete fix Fixed autocomplete returning both city and name if any of them matched regex --- routes/routeSearch.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/routes/routeSearch.js b/routes/routeSearch.js index 3eab1ba..dc1fae7 100644 --- a/routes/routeSearch.js +++ b/routes/routeSearch.js @@ -84,8 +84,12 @@ router.get("/autocomplete/", (req, res) => { res.sendStatus(404); } else { doc.forEach((value) => { - cities.add(value.city); - restaurants.add(value.name); + if(value.city.search(regex) !== -1){ + cities.add(value.city); + } + if(value.name.search(regex) !== -1){ + restaurants.add(value.name); + } }); res.send({ cities: Array.from(cities), @@ -93,7 +97,7 @@ router.get("/autocomplete/", (req, res) => { }); } } - ).limit(5); + ).limit(10); } else { res.send({ cities: [],