diff --git a/js/places.js b/js/places.js index 0ba2821..51c3a9d 100644 --- a/js/places.js +++ b/js/places.js @@ -180,13 +180,26 @@ export class PlaceDatabase extends EventTarget { this.fullTextIndex = lunr(function(){ this.ref("id") - this.field("name") + this.field("name", {boost: 3}) + this.field("name_simple", {boost: 2}) this.field("synonyms") for(let [id, feature] of Object.entries(database.featuresById)){ let sym = feature.mapSymbol; let synonyms = [] + let name_simple = null; + + if(feature.properties.name){ + let sinDiacritics = feature.properties.name.normalize("NFD") + .replace(/[\u0300-\u036f]/g, ""); + + name_simple = sinDiacritics.toLowerCase(); + + synonyms.push(feature.properties.name.toLowerCase()) + synonyms.push(sinDiacritics) + synonyms.push(sinDiacritics.toLowerCase()) + } if(sym.genericName){ synonyms.push(sym.genericName) @@ -200,11 +213,18 @@ export class PlaceDatabase extends EventTarget { showOnEmptyMap.push(feature) } + let boost = undefined; + + if(sym.searchBoost !== undefined){ + boost = sym.searchBoost + } + this.add({ id, name: feature.properties.name || sym.genericName, + name_simple, synonyms - }) + }, {boost}) } }) diff --git a/js/symbols.js b/js/symbols.js index 6acefee..a35123f 100644 --- a/js/symbols.js +++ b/js/symbols.js @@ -32,6 +32,11 @@ export class MapSymbol { */ genericName = undefined + /** + * Boost features with this symbol up (or down if negative) in search if defined + */ + searchBoost = undefined + /** * A list of sysnonyms for this feature for full text indexing * @type {string[]} @@ -300,6 +305,7 @@ export const VERBOTEN_AREA_SYMBOL = new MapSymbol() VERBOTEN_AREA_SYMBOL.genericName = "Zone interdite" VERBOTEN_AREA_SYMBOL.backgroundColor = "#992700" VERBOTEN_AREA_SYMBOL.borderColor = "#992700" + VERBOTEN_AREA_SYMBOL.searchBoost = -2; } export const BUILDING_SYMBOL = new MapSymbol()