From cebbdfce53f5c795f01be32379b455caba84b5d0 Mon Sep 17 00:00:00 2001 From: Niclas Edenvin Date: Mon, 9 Dec 2024 09:48:31 +0000 Subject: [PATCH] Merged in fix/sw-1110-search-suggestions (pull request #1046) fix(sw-1110): only match search keywords from start of word * fix(sw-1110): only match search keywords from start of word This changes the search field so when it tries to match on a keyword it has to match from the beginning of the word, not anywhere in the word Approved-by: Bianca Widstam --- .../Forms/BookingWidget/FormContent/Search/reducer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/Forms/BookingWidget/FormContent/Search/reducer.ts b/components/Forms/BookingWidget/FormContent/Search/reducer.ts index 4c42a2507..dd7bb1f8c 100644 --- a/components/Forms/BookingWidget/FormContent/Search/reducer.ts +++ b/components/Forms/BookingWidget/FormContent/Search/reducer.ts @@ -41,11 +41,13 @@ export function reducer(state: State, action: Action) { const search = action.payload.search.toLowerCase() state.defaultLocations.forEach((location) => { const locationName = location.name.toLowerCase() - const keyWords = location.keyWords?.map((l) => l.toLowerCase()) + const keyWords = location.keyWords?.flatMap((l) => + l.toLowerCase().split(" ") + ) if (locationName.includes(search.trim())) { matchesMap.set(location.name, location) } - if (keyWords?.find((keyWord) => keyWord.includes(search.trim()))) { + if (keyWords?.find((keyWord) => keyWord.startsWith(search.trim()))) { matchesMap.set(location.name, location) } })