forked from MapComplete/MapComplete
Add search for filters
This commit is contained in:
parent
1378c1a779
commit
c94393e825
24 changed files with 405 additions and 254 deletions
|
@ -13,11 +13,17 @@ export default class FilterSearch implements GeocodingProvider {
|
|||
}
|
||||
|
||||
async search(query: string, options?: GeocodingOptions): Promise<SearchResult[]> {
|
||||
return []
|
||||
return this.searchDirectly(query)
|
||||
}
|
||||
|
||||
private searchDirectly(query: string): SearchResult[] {
|
||||
const possibleFilters: SearchResult[] = []
|
||||
if (query.length === 0) {
|
||||
return []
|
||||
}
|
||||
if(!Utils.isEmoji(query)){
|
||||
query = Utils.simplifyStringForSearch(query)
|
||||
}
|
||||
for (const layer of this._state.layout.layers) {
|
||||
if (!Array.isArray(layer.filters)) {
|
||||
continue
|
||||
|
@ -26,16 +32,16 @@ export default class FilterSearch implements GeocodingProvider {
|
|||
for (let i = 0; i < filter.options.length; i++) {
|
||||
const option = filter.options[i]
|
||||
if (option === undefined) {
|
||||
console.log("No options for", filter)
|
||||
continue
|
||||
}
|
||||
const terms = [option.question.txt,
|
||||
...(option.searchTerms?.[Locale.language.data] ?? option.searchTerms?.["en"] ?? [])].flatMap(term => term.split(" "))
|
||||
let terms = ([option.question.txt,
|
||||
...(option.searchTerms?.[Locale.language.data] ?? option.searchTerms?.["en"] ?? [])]
|
||||
.flatMap(term => [term, ...term?.split(" ")]))
|
||||
terms = terms.map(t => Utils.simplifyStringForSearch(t))
|
||||
terms.push(option.emoji)
|
||||
Utils.NoNullInplace(terms)
|
||||
const levehnsteinD = Math.min(...
|
||||
terms.map(entry => {
|
||||
const simplified = Utils.simplifyStringForSearch(entry)
|
||||
return Utils.levenshteinDistance(query, simplified.slice(0, query.length))
|
||||
}))
|
||||
terms.map(entry => Utils.levenshteinDistance(query, entry.slice(0, query.length))))
|
||||
if (levehnsteinD / query.length > 0.25) {
|
||||
continue
|
||||
}
|
||||
|
@ -51,8 +57,10 @@ export default class FilterSearch implements GeocodingProvider {
|
|||
}
|
||||
|
||||
suggest(query: string, options?: GeocodingOptions): Store<SearchResult[]> {
|
||||
if (Utils.isEmoji(query)) {
|
||||
return new ImmutableStore(this.searchDirectly(query))
|
||||
}
|
||||
query = Utils.simplifyStringForSearch(query)
|
||||
|
||||
return new ImmutableStore(this.searchDirectly(query))
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ export class RecentSearch {
|
|||
}
|
||||
results.push(simple)
|
||||
}
|
||||
console.log("Setting", results)
|
||||
prefs.setData(JSON.stringify(results))
|
||||
|
||||
})
|
||||
|
@ -59,7 +58,6 @@ export class RecentSearch {
|
|||
if (!osm_id) {
|
||||
return
|
||||
}
|
||||
console.log("Selected element is", selected)
|
||||
if (["node", "way", "relation"].indexOf(osm_type) < 0) {
|
||||
return
|
||||
}
|
||||
|
@ -86,7 +84,6 @@ export class RecentSearch {
|
|||
seenIds.add(id)
|
||||
}
|
||||
}
|
||||
console.log(">>>", arr)
|
||||
this._seenThisSession.set(arr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue