]> git.openstreetmap.org Git - nominatim.git/commitdiff
ignore POIs with inherited addresses for the address layer
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 2 Apr 2025 08:09:49 +0000 (10:09 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 2 Apr 2025 08:30:45 +0000 (10:30 +0200)
We know that there is a building which describes the address as a
polygon and is therefore more suitable.

src/nominatim_api/sql/sqlalchemy_functions.py
test/python/api/test_api_reverse.py

index 81fc83d6c4ddd875b2616a44cb88480796cf244f..00830f33b025db286e570792541ff3f3a3ec345e 100644 (file)
@@ -122,15 +122,18 @@ class IsAddressPoint(sa.sql.functions.GenericFunction[Any]):
 
     def __init__(self, table: sa.Table) -> None:
         super().__init__(table.c.rank_address,
-                         table.c.housenumber, table.c.name)
+                         table.c.housenumber, table.c.name, table.c.address)
 
 
 @compiles(IsAddressPoint)
 def default_is_address_point(element: IsAddressPoint,
                              compiler: 'sa.Compiled', **kw: Any) -> str:
-    rank, hnr, name = list(element.clauses)
-    return "(%s = 30 AND (%s IS NOT NULL OR %s ? 'addr:housename'))" % (
+    rank, hnr, name, address = list(element.clauses)
+    return "(%s = 30 AND (%s IS NULL OR NOT %s ? '_inherited')" \
+           " AND (%s IS NOT NULL OR %s ? 'addr:housename'))" % (
                 compiler.process(rank, **kw),
+                compiler.process(address, **kw),
+                compiler.process(address, **kw),
                 compiler.process(hnr, **kw),
                 compiler.process(name, **kw))
 
@@ -138,9 +141,11 @@ def default_is_address_point(element: IsAddressPoint,
 @compiles(IsAddressPoint, 'sqlite')
 def sqlite_is_address_point(element: IsAddressPoint,
                             compiler: 'sa.Compiled', **kw: Any) -> str:
-    rank, hnr, name = list(element.clauses)
-    return "(%s = 30 AND coalesce(%s, json_extract(%s, '$.addr:housename')) IS NOT NULL)" % (
+    rank, hnr, name, address = list(element.clauses)
+    return "(%s = 30 AND json_extract(%s, '$._inherited') IS NULL" \
+           " AND coalesce(%s, json_extract(%s, '$.addr:housename')) IS NOT NULL)" % (
                 compiler.process(rank, **kw),
+                compiler.process(address, **kw),
                 compiler.process(hnr, **kw),
                 compiler.process(name, **kw))
 
index 91074ecb3ef8e7ccdd8b1288f4d027a60bc25775..d7d3ba7ee4aca4dfb546e811b16a2ba3e2b7d825 100644 (file)
@@ -68,7 +68,8 @@ def test_reverse_ignore_unindexed(apiobj, frontend):
                           (0.7, napi.DataLayer.NATURAL, 227),
                           (0.70003, napi.DataLayer.MANMADE | napi.DataLayer.RAILWAY, 225),
                           (0.70003, napi.DataLayer.MANMADE | napi.DataLayer.NATURAL, 225),
-                          (5, napi.DataLayer.ADDRESS, 229)])
+                          (5, napi.DataLayer.ADDRESS, 229),
+                          (5.0001, napi.DataLayer.ADDRESS, 229)])
 def test_reverse_rank_30_layers(apiobj, frontend, y, layer, place_id):
     apiobj.add_placex(place_id=223, osm_type='N', class_='place', type='house',
                       housenumber='1',
@@ -96,6 +97,12 @@ def test_reverse_rank_30_layers(apiobj, frontend, y, layer, place_id):
                       rank_address=30,
                       rank_search=30,
                       centroid=(1.3, 5))
+    apiobj.add_placex(place_id=230, class_='place', type='house',
+                      housenumber='2',
+                      address={'_inherited': ''},
+                      rank_address=30,
+                      rank_search=30,
+                      centroid=(1.3, 5.0001))
 
     api = frontend(apiobj, options=API_OPTIONS)
     assert api.reverse((1.3, y), layers=layer).place_id == place_id