From 5d4c29b84b3296d6278aa39d48b50dedd3b4a131 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 28 Oct 2025 17:20:17 +0100 Subject: [PATCH] force inclusion of extratags used directly by Nominatim --- docs/admin/Migration.md | 12 +++++ docs/customize/Import-Styles.md | 6 +-- lib-lua/themes/nominatim/init.lua | 47 +++++++++---------- lib-lua/themes/nominatim/presets.lua | 6 +-- lib-lua/themes/nominatim/topics/address.lua | 1 - lib-lua/themes/nominatim/topics/admin.lua | 1 - lib-lua/themes/nominatim/topics/full.lua | 1 - lib-lua/themes/nominatim/topics/street.lua | 1 - .../features/osm2pgsql/import/simple.feature | 23 +++++++++ 9 files changed, 61 insertions(+), 37 deletions(-) diff --git a/docs/admin/Migration.md b/docs/admin/Migration.md index becf2f7b..2ebb8889 100644 --- a/docs/admin/Migration.md +++ b/docs/admin/Migration.md @@ -17,6 +17,18 @@ breaking changes. **Please read them before running the migration.** and migrate to 4.3 first. Then you can migrate to the current version. It is strongly recommended to do a reimport instead. +## 5.1.0 -> 5.2.0 + +### Lua import style: required extratags removed + +Tags that are required by Nominatim as extratags are now always included +independent of what is defined in the style. The line + + flex.add_for_extratags('required') + +is no longer required in custom styles and will throw an error. Simply +remove the line from your style. + ## 4.5.0 -> 5.0.0 ### PHP frontend removed diff --git a/docs/customize/Import-Styles.md b/docs/customize/Import-Styles.md index 102fd723..9f0fe11e 100644 --- a/docs/customize/Import-Styles.md +++ b/docs/customize/Import-Styles.md @@ -267,11 +267,7 @@ in turn take precedence over prefix matches. ##### Presets -| Name | Description | -| :----- | :---------- | -| required | Tags that Nominatim will use for various computations when present in extratags. Automatically added. | - -In addition, all [presets from ignored tags](#presets_1) are accepted. +Accepts all [presets from ignored tags](#presets_1). ### General pre-filtering diff --git a/lib-lua/themes/nominatim/init.lua b/lib-lua/themes/nominatim/init.lua index 850fdaf9..8720a631 100644 --- a/lib-lua/themes/nominatim/init.lua +++ b/lib-lua/themes/nominatim/init.lua @@ -29,6 +29,7 @@ local NAME_FILTER = nil local ADDRESS_TAGS = {} local ADDRESS_FILTER = nil local EXTRATAGS_FILTER +local REQUIRED_EXTRATAGS_FILTER local POSTCODE_FALLBACK = true local ENTRANCE_FUNCTION = nil @@ -165,24 +166,6 @@ local function address_fallback(place) return place:clone{names=names} end ---------- Built-in extratags transformation functions --------------- - -local function default_extratags_filter(p, k) - -- Default handling is to copy over place tag for boundaries. - -- Nominatim needs this. - if k ~= 'boundary' or p.intags.place == nil then - return p.extratags - end - - local extra = { place = p.intags.place } - for kin, vin in pairs(p.extratags) do - extra[kin] = vin - end - - return extra -end -EXTRATAGS_FILTER = default_extratags_filter - ----------------- other helper functions ----------------------------- local function lookup_prefilter_classification(k, v) @@ -444,10 +427,17 @@ function Place:write_row(k, v) return 0 end - local extratags = EXTRATAGS_FILTER(self, k, v) - if not (extratags and next(extratags)) then - extratags = nil - end + local extra = EXTRATAGS_FILTER(self, k, v) or {} + + for tk, tv in pairs(self.object.tags) do + if REQUIRED_EXTRATAGS_FILTER(tk, tv) and extra[tk] == nil then + extra[tk] = tv + end + end + + if extra and next(extra) == nil then + extra = nil + end insert_row.place{ class = k, @@ -455,7 +445,7 @@ function Place:write_row(k, v) admin_level = self.admin_level, name = next(self.names) and self.names, address = next(self.address) and self.address, - extratags = extratags, + extratags = extra, geometry = self.geometry } @@ -712,6 +702,15 @@ function module.process_tags(o) end end +--------- Extratags post-processing functions --------------- + +local function default_extratags_filter(p, k) + return p.extratags +end + +EXTRATAGS_FILTER = default_extratags_filter +REQUIRED_EXTRATAGS_FILTER = module.tag_match(PRESETS.EXTRATAGS) + --------- Convenience functions for simple style configuration ----------------- function module.set_prefilters(data) @@ -742,7 +741,7 @@ end function module.add_for_extratags(data) if type(data) == 'string' then local preset = data - data = PRESETS.EXTRATAGS[data] or PRESETS.IGNORE_KEYS[data] + data = PRESETS.IGNORE_KEYS[data] if data == nil then error('Unknown preset for extratags: ' .. preset) end diff --git a/lib-lua/themes/nominatim/presets.lua b/lib-lua/themes/nominatim/presets.lua index 3cb09e75..12c93a14 100644 --- a/lib-lua/themes/nominatim/presets.lua +++ b/lib-lua/themes/nominatim/presets.lua @@ -375,11 +375,9 @@ module.IGNORE_KEYS.address = {'addr:street:*', 'addr:city:*', 'addr:district:*', 'addr:province:*', 'addr:subdistrict:*', 'addr:place:*', 'addr:TW:dataset'} --- Extra tags (prefiltered away) +-- INTERNAL: Required extra tags -module.EXTRATAGS = {} - -module.EXTRATAGS.required = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'} +module.EXTRATAGS = {keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'}} -- Defaults for the entrance table diff --git a/lib-lua/themes/nominatim/topics/address.lua b/lib-lua/themes/nominatim/topics/address.lua index 0e813673..faa04c65 100644 --- a/lib-lua/themes/nominatim/topics/address.lua +++ b/lib-lua/themes/nominatim/topics/address.lua @@ -11,7 +11,6 @@ flex.set_address_tags('core') flex.modify_address_tags('houses') flex.ignore_keys('metatags') -flex.add_for_extratags('required') if cfg.with_extratags then flex.set_unused_handling{delete_keys = {'tiger:*'}} diff --git a/lib-lua/themes/nominatim/topics/admin.lua b/lib-lua/themes/nominatim/topics/admin.lua index 47f4e248..7db8e616 100644 --- a/lib-lua/themes/nominatim/topics/admin.lua +++ b/lib-lua/themes/nominatim/topics/admin.lua @@ -8,7 +8,6 @@ flex.set_address_tags('core') flex.set_postcode_fallback(false) flex.ignore_keys('metatags') -flex.add_for_extratags('required') if cfg.with_extratags then flex.set_unused_handling{delete_keys = {'tiger:*'}} diff --git a/lib-lua/themes/nominatim/topics/full.lua b/lib-lua/themes/nominatim/topics/full.lua index c9b1b467..489fead8 100644 --- a/lib-lua/themes/nominatim/topics/full.lua +++ b/lib-lua/themes/nominatim/topics/full.lua @@ -20,7 +20,6 @@ flex.set_address_tags('core') flex.modify_address_tags('houses') flex.ignore_keys('metatags') -flex.add_for_extratags('required') if cfg.with_extratags then flex.set_unused_handling{delete_keys = {'tiger:*'}} diff --git a/lib-lua/themes/nominatim/topics/street.lua b/lib-lua/themes/nominatim/topics/street.lua index 89bed442..5c78906f 100644 --- a/lib-lua/themes/nominatim/topics/street.lua +++ b/lib-lua/themes/nominatim/topics/street.lua @@ -10,7 +10,6 @@ flex.set_address_tags('core') flex.set_postcode_fallback(false) flex.ignore_keys('metatags') -flex.add_for_extratags('required') if cfg.with_extratags then flex.set_unused_handling{delete_keys = {'tiger:*'}} diff --git a/test/bdd/features/osm2pgsql/import/simple.feature b/test/bdd/features/osm2pgsql/import/simple.feature index 217c2b7c..8581fc36 100644 --- a/test/bdd/features/osm2pgsql/import/simple.feature +++ b/test/bdd/features/osm2pgsql/import/simple.feature @@ -40,3 +40,26 @@ Feature: Import of simple objects by osm2pgsql Then place contains exactly | object | class | type | | N1 | place | house | + + Scenario Outline: Tags used by Nominatim internally are always imported + Given the lua style file + """ + local flex = require('import-