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
This commit is contained in:
Niclas Edenvin
2024-12-09 09:48:31 +00:00
parent 743bc9cad2
commit cebbdfce53

View File

@@ -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)
}
})