From 006e0e5c76f08d906261681372dda89637ce2358 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 9 Dec 2024 17:28:30 +0100 Subject: [PATCH] do not save names when falling back to addresses If an object doesn't have a useable main tag, then the names should always be ignored, independently of the presence of housenumbers. We have to assume that the name belongs to a feature that was intentionally filtered out. --- lib-lua/themes/nominatim/init.lua | 20 ++++++++++++++++++-- settings/address-levels.json | 8 ++++++++ test/bdd/api/search/queries.feature | 2 +- test/bdd/osm2pgsql/import/tags.feature | 13 +++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib-lua/themes/nominatim/init.lua b/lib-lua/themes/nominatim/init.lua index 6d3804e274..dacaaae8ec 100644 --- a/lib-lua/themes/nominatim/init.lua +++ b/lib-lua/themes/nominatim/init.lua @@ -134,6 +134,22 @@ function PlaceTransform.named_with_key(place, k) end end +-- Special transform used with address fallbacks: ignore all names +-- except for those marked as being part of the address. +local function address_fallback(place) + if next(place.names) == nil or NAMES.house == nil then + return place + end + + local names = {} + for k, v in pairs(place.names) do + if NAME_FILTER(k, v) == 'house' then + names[k] = v + end + end + return place:clone{names=names} +end + --------- Built-in extratags transformation functions --------------- local function default_extratags_filter(p, k) @@ -379,7 +395,7 @@ function Place:grab_name_parts(data) self.has_name = true elseif atype == 'house' then self.has_name = true - fallback = {'place', 'house', PlaceTransform.always} + fallback = {'place', 'house', address_fallback} end end end @@ -636,7 +652,7 @@ function module.process_tags(o) -- address keys if o:grab_address_parts{groups=ADDRESS_FILTER} > 0 and fallback == nil then - fallback = {'place', 'house', PlaceTransform.always} + fallback = {'place', 'house', address_fallback} end if o.address.country ~= nil and #o.address.country ~= 2 then o.address['country'] = nil diff --git a/settings/address-levels.json b/settings/address-levels.json index b63eac4efa..a82133ef0d 100644 --- a/settings/address-levels.json +++ b/settings/address-levels.json @@ -74,6 +74,14 @@ "stone" : 30, "" : [22, 0] }, + "water" : { + "lake" : [20, 0], + "reservoir" : [20, 0], + "wastewater" : [24, 0], + "pond" : [24, 0], + "fountain" : [24, 0], + "" : [22, 0] + }, "waterway" : { "river" : [19, 0], "stream" : [22, 0], diff --git a/test/bdd/api/search/queries.feature b/test/bdd/api/search/queries.feature index 6e640accab..3b06af7862 100644 --- a/test/bdd/api/search/queries.feature +++ b/test/bdd/api/search/queries.feature @@ -192,7 +192,7 @@ Feature: Search queries Then exactly 1 result is returned And results contain | class | - | natural | + | water | Examples: | data | diff --git a/test/bdd/osm2pgsql/import/tags.feature b/test/bdd/osm2pgsql/import/tags.feature index 8df726ca1d..2a7673b758 100644 --- a/test/bdd/osm2pgsql/import/tags.feature +++ b/test/bdd/osm2pgsql/import/tags.feature @@ -256,3 +256,16 @@ Feature: Tag evaluation | N21:natural | water | | N23:water | pond | | N26:natural | water | + + Scenario: Drop name for address fallback + When loading osm data + """ + n1 Taddr:housenumber=23,name=Foo + n2 Taddr:housenumber=23,addr:housename=Foo + n3 Taddr:housenumber=23 + """ + Then place contains exactly + | object | type | address | name | + | N1:place | house | 'housenumber': '23' | - | + | N2:place | house | 'housenumber': '23' | 'addr:housename': 'Foo' | + | N3:place | house | 'housenumber': '23' | - |