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:
@@ -41,11 +41,13 @@ export function reducer(state: State, action: Action) {
|
|||||||
const search = action.payload.search.toLowerCase()
|
const search = action.payload.search.toLowerCase()
|
||||||
state.defaultLocations.forEach((location) => {
|
state.defaultLocations.forEach((location) => {
|
||||||
const locationName = location.name.toLowerCase()
|
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())) {
|
if (locationName.includes(search.trim())) {
|
||||||
matchesMap.set(location.name, location)
|
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)
|
matchesMap.set(location.name, location)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user