forked from MapComplete/MapComplete
Search: layersearch now splits based on word, to detect single words which match
This commit is contained in:
parent
ed2bec139c
commit
c176c6adae
1 changed files with 3 additions and 1 deletions
|
@ -3,6 +3,7 @@ import SearchUtils from "./SearchUtils"
|
|||
import ThemeSearch from "./ThemeSearch"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import { Utils } from "../../Utils"
|
||||
|
||||
export default class LayerSearch {
|
||||
|
||||
|
@ -15,12 +16,13 @@ export default class LayerSearch {
|
|||
|
||||
static scoreLayers(query: string, layerWhitelist?: Set<string>): Record<string, number> {
|
||||
const result: Record<string, number> = {}
|
||||
const queryParts = query.trim().split(" ").map(q => Utils.simplifyStringForSearch(q))
|
||||
for (const id in ThemeSearch.officialThemes.layers) {
|
||||
if(layerWhitelist !== undefined && !layerWhitelist.has(id)){
|
||||
continue
|
||||
}
|
||||
const keywords = ThemeSearch.officialThemes.layers[id]
|
||||
const distance = SearchUtils.scoreKeywords(query, keywords)
|
||||
const distance = Math.min(... queryParts.map(q => SearchUtils.scoreKeywords(q, keywords)))
|
||||
result[id] = distance
|
||||
}
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue