forked from MapComplete/MapComplete
		
	Add priority-search to the searchable element
This commit is contained in:
		
							parent
							
								
									c916d5fe66
								
							
						
					
					
						commit
						07973e37a6
					
				
					 14 changed files with 5349 additions and 244 deletions
				
			
		|  | @ -234,11 +234,11 @@ class LayerOverviewUtils { | |||
|         this.checkAllSvgs() | ||||
|          | ||||
|         if(AllKnownLayouts.getSharedLayersConfigs().size == 0){ | ||||
|             throw "This was a bootstrapping-run. Run generate layeroverview again!" | ||||
|             console.error( "This was a bootstrapping-run. Run generate layeroverview again!") | ||||
|         }else{ | ||||
|             const green = s => '\x1b[92m' + s + '\x1b[0m' | ||||
|             console.log(green("All done!")) | ||||
|         } | ||||
| 
 | ||||
|         const green = s => '\x1b[92m' + s + '\x1b[0m' | ||||
|         console.log(green("All done!")) | ||||
|     } | ||||
| 
 | ||||
|     private buildLayerIndex(doesImageExist: DoesImageExist, forceReload: boolean): Map<string, LayerConfigJson> { | ||||
|  |  | |||
|  | @ -7,14 +7,18 @@ import {existsSync, mkdirSync, readFileSync, writeFileSync} from "fs"; | |||
| import {LayerConfigJson} from "../../Models/ThemeConfig/Json/LayerConfigJson"; | ||||
| import {MappingConfigJson} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"; | ||||
| import LanguageUtils from "../../Utils/LanguageUtils"; | ||||
| 
 | ||||
| import * as perCountry from "../../assets/language_in_country.json" | ||||
| import {Utils} from "../../Utils"; | ||||
| function main(){ | ||||
|     const sourcepath = "assets/generated/languages-wd.json"; | ||||
|     console.log(`Converting language data file '${sourcepath}' into a tagMapping`) | ||||
|     const languages = WikidataUtils.extractLanguageData(JSON.parse(readFileSync(sourcepath, "utf8")), {}) | ||||
|     const mappings : MappingConfigJson[] = [] | ||||
|     const schoolmappings : MappingConfigJson[] = [] | ||||
| 
 | ||||
|      | ||||
|     const countryToLanguage : Record<string, string[]> = perCountry | ||||
|     const officialLanguagesPerCountry = Utils.TransposeMap(countryToLanguage); | ||||
|      | ||||
|     languages.forEach((l, code) => { | ||||
|         const then : Record<string, string>= {} | ||||
|         l.forEach((tr, lng) => { | ||||
|  | @ -24,18 +28,26 @@ function main(){ | |||
|             } | ||||
|             then[languageCodeWeblate] = tr | ||||
|         }) | ||||
|          | ||||
|         const officialCountries = Utils.Dedup(officialLanguagesPerCountry[code]?.map(s => s.toLowerCase()) ?? []) | ||||
|         const prioritySearch = officialCountries.length > 0 ? "_country~" + officialCountries.map(c => "((^|;)"+c+"($|;))").join("|") : undefined | ||||
|         mappings.push(<MappingConfigJson>{ | ||||
|             if: "language:" + code + "=yes", | ||||
|             ifnot: "language:" + code + "=", | ||||
|             searchTerms: { | ||||
|                 "*": [code] | ||||
|             }, | ||||
|             then | ||||
|             then, | ||||
|             priorityIf: prioritySearch | ||||
|         }) | ||||
| 
 | ||||
|        schoolmappings.push(<MappingConfigJson>{ | ||||
|             if: "school:language=" + code, | ||||
|             then | ||||
|             then, | ||||
|             priorityIf: prioritySearch, | ||||
|             searchTerms: { | ||||
|                 "*":[code] | ||||
|            } | ||||
|         }) | ||||
|     }) | ||||
|      | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue