Diacritiques ignorés dans la recherche et ajustement des boosts

This commit is contained in:
EpicKiwi 2026-06-28 17:20:22 +02:00
parent f677fba85a
commit 0db54f17cd
Signed by: epickiwi
GPG key ID: C4B28FD2729941CE
2 changed files with 28 additions and 2 deletions

View file

@ -180,13 +180,26 @@ export class PlaceDatabase extends EventTarget {
this.fullTextIndex = lunr(function(){ this.fullTextIndex = lunr(function(){
this.ref("id") this.ref("id")
this.field("name") this.field("name", {boost: 3})
this.field("name_simple", {boost: 2})
this.field("synonyms") this.field("synonyms")
for(let [id, feature] of Object.entries(database.featuresById)){ for(let [id, feature] of Object.entries(database.featuresById)){
let sym = feature.mapSymbol; let sym = feature.mapSymbol;
let synonyms = [] 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){ if(sym.genericName){
synonyms.push(sym.genericName) synonyms.push(sym.genericName)
@ -200,11 +213,18 @@ export class PlaceDatabase extends EventTarget {
showOnEmptyMap.push(feature) showOnEmptyMap.push(feature)
} }
let boost = undefined;
if(sym.searchBoost !== undefined){
boost = sym.searchBoost
}
this.add({ this.add({
id, id,
name: feature.properties.name || sym.genericName, name: feature.properties.name || sym.genericName,
name_simple,
synonyms synonyms
}) }, {boost})
} }
}) })

View file

@ -32,6 +32,11 @@ export class MapSymbol {
*/ */
genericName = undefined 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 * A list of sysnonyms for this feature for full text indexing
* @type {string[]} * @type {string[]}
@ -300,6 +305,7 @@ export const VERBOTEN_AREA_SYMBOL = new MapSymbol()
VERBOTEN_AREA_SYMBOL.genericName = "Zone interdite" VERBOTEN_AREA_SYMBOL.genericName = "Zone interdite"
VERBOTEN_AREA_SYMBOL.backgroundColor = "#992700" VERBOTEN_AREA_SYMBOL.backgroundColor = "#992700"
VERBOTEN_AREA_SYMBOL.borderColor = "#992700" VERBOTEN_AREA_SYMBOL.borderColor = "#992700"
VERBOTEN_AREA_SYMBOL.searchBoost = -2;
} }
export const BUILDING_SYMBOL = new MapSymbol() export const BUILDING_SYMBOL = new MapSymbol()