From f1fbc04f33c2b8755711c90ded56086bf1bfd05b Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 28 Oct 2025 14:33:45 +0100 Subject: [PATCH] harmonize use of callback with set_entrance_filter All other functions except a simple function, so do this here as well. --- docs/customize/Import-Styles.md | 12 ++++++------ lib-lua/themes/nominatim/init.lua | 11 ++++++++--- lib-lua/themes/nominatim/presets.lua | 6 +++--- test/bdd/features/osm2pgsql/import/entrances.feature | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/customize/Import-Styles.md b/docs/customize/Import-Styles.md index 35ff07cf..102fd723 100644 --- a/docs/customize/Import-Styles.md +++ b/docs/customize/Import-Styles.md @@ -76,8 +76,8 @@ and may be returned with the result [on request](../api/Search.md#output-details !!! danger Some tags in the extratags category are used by Nominatim to better - classify the place. You want to make sure these are always present - in custom styles. + classify the place. These tags will always be added, independent of + any settings in the style. Configuring the style means deciding which key and/or key/value is used in which category. @@ -269,7 +269,7 @@ in turn take precedence over prefix matches. | Name | Description | | :----- | :---------- | -| required | Tags that Nominatim will use for various computations when present in extratags. Always include these. | +| 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. @@ -462,9 +462,9 @@ with a table with the following fields: will always be excluded, independently of this setting. To have even more fine-grained control over the output, you can also hand -in a table with a single field `func` containing a callback for processing -entrance information. The callback function receives a single parameter, -the [osm2pgsql object](https://osm2pgsql.org/doc/manual.html#processing-callbacks). +in a callback for processing entrance information. The callback function +receives a single parameter, the +[osm2pgsql object](https://osm2pgsql.org/doc/manual.html#processing-callbacks). This object itself must not be modified. The callback should return either `nil` when the object is not an entrance. Or it returns a table with a mandatory `entrance` field containing a string with the type of entrance diff --git a/lib-lua/themes/nominatim/init.lua b/lib-lua/themes/nominatim/init.lua index 228e5c55..850fdaf9 100644 --- a/lib-lua/themes/nominatim/init.lua +++ b/lib-lua/themes/nominatim/init.lua @@ -943,17 +943,22 @@ function module.set_relation_types(data) end function module.set_entrance_filter(data) + if data == nil or type(data) == 'function' then + ENTRANCE_FUNCTION = data + return nil + end + if type(data) == 'string' then local preset = data - data = PRESETS.ENTRACE_TABLE[data] + data = PRESETS.ENTRANCE_TABLE[data] if data == nil then error('Unknown preset for entrance table: ' .. preset) end end - ENTRANCE_FUNCTION = data and data.func + ENTRANCE_FUNCTION = nil - if data ~= nil and data.main_tags ~= nil and next(data.main_tags) ~= nil then + if data.main_tags ~= nil and next(data.main_tags) ~= nil then if data.extra_include ~= nil and next(data.extra_include) == nil then -- shortcut: no extra tags requested ENTRANCE_FUNCTION = function(o) diff --git a/lib-lua/themes/nominatim/presets.lua b/lib-lua/themes/nominatim/presets.lua index 7408d4af..3cb09e75 100644 --- a/lib-lua/themes/nominatim/presets.lua +++ b/lib-lua/themes/nominatim/presets.lua @@ -383,9 +383,9 @@ module.EXTRATAGS.required = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'} -- Defaults for the entrance table -module.ENTRACE_TABLE = {} +module.ENTRANCE_TABLE = {} -module.ENTRACE_TABLE.default = {main_tags = {'entrance', 'routing:entrance'}, - extra_exclude = module.IGNORE_KEYS.metatags} +module.ENTRANCE_TABLE.default = {main_tags = {'entrance', 'routing:entrance'}, + extra_exclude = module.IGNORE_KEYS.metatags} return module diff --git a/test/bdd/features/osm2pgsql/import/entrances.feature b/test/bdd/features/osm2pgsql/import/entrances.feature index 3999743b..0d4fb16e 100644 --- a/test/bdd/features/osm2pgsql/import/entrances.feature +++ b/test/bdd/features/osm2pgsql/import/entrances.feature @@ -109,9 +109,9 @@ Feature: Import of entrance objects by osm2pgsql Given the lua style file """ local flex = require('import-full') - flex.set_entrance_filter{func = function(object) + flex.set_entrance_filter(function(object) return {entrance='always', extratags = {ref = '1'}} - end} + end) """ When loading osm data """ -- 2.39.5