From b2319e52ff8c995eb3350098811cbabc29b32f51 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 28 Nov 2023 17:53:37 +0100 Subject: [PATCH] correctly exclude streets with housenumber searches Street result are not subject to the full filtering in the SQL query, so recheck. --- nominatim/api/search/db_searches.py | 13 +++++--- test/python/api/search/test_search_places.py | 31 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/nominatim/api/search/db_searches.py b/nominatim/api/search/db_searches.py index ce5fbc63..232f816e 100644 --- a/nominatim/api/search/db_searches.py +++ b/nominatim/api/search/db_searches.py @@ -766,9 +766,6 @@ class PlaceSearch(AbstractSearch): assert result result.bbox = Bbox.from_wkb(row.bbox) result.accuracy = row.accuracy - if not details.excluded or not result.place_id in details.excluded: - results.append(result) - if self.housenumbers and row.rank_address < 30: if row.placex_hnr: subs = _get_placex_housenumbers(conn, row.placex_hnr, details) @@ -788,6 +785,14 @@ class PlaceSearch(AbstractSearch): sub.accuracy += 0.6 results.append(sub) - result.accuracy += 1.0 # penalty for missing housenumber + # Only add the street as a result, if it meets all other + # filter conditions. + if (not details.excluded or result.place_id not in details.excluded)\ + and (not self.qualifiers or result.category in self.qualifiers.values)\ + and result.rank_address >= details.min_rank: + result.accuracy += 1.0 # penalty for missing housenumber + results.append(result) + else: + results.append(result) return results diff --git a/test/python/api/search/test_search_places.py b/test/python/api/search/test_search_places.py index 3853439f..8a363e97 100644 --- a/test/python/api/search/test_search_places.py +++ b/test/python/api/search/test_search_places.py @@ -281,6 +281,37 @@ class TestStreetWithHousenumber: assert [r.place_id for r in results] == [2, 92, 2000] + def test_lookup_only_house_qualifier(self, apiobj): + lookup = FieldLookup('name_vector', [1,2], 'lookup_all') + ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])]) + + results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'], + quals=[('place', 'house')]) + + assert [r.place_id for r in results] == [2, 92] + + + def test_lookup_only_street_qualifier(self, apiobj): + lookup = FieldLookup('name_vector', [1,2], 'lookup_all') + ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])]) + + results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'], + quals=[('highway', 'residential')]) + + assert [r.place_id for r in results] == [1000, 2000] + + + @pytest.mark.parametrize('rank,found', [(26, True), (27, False), (30, False)]) + def test_lookup_min_rank(self, apiobj, rank, found): + lookup = FieldLookup('name_vector', [1,2], 'lookup_all') + ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])]) + + results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'], + details=SearchDetails(min_rank=rank)) + + assert [r.place_id for r in results] == ([2, 92, 1000, 2000] if found else [2, 92]) + + @pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON, napi.GeometryFormat.KML, napi.GeometryFormat.SVG, -- 2.39.5