From: Sarah Hoffmann Date: Tue, 28 Nov 2023 11:01:49 +0000 (+0100) Subject: the category parameter in search should result in a qualifier X-Git-Tag: v4.4.0~75^2~3 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/70dc4957dc41df7d808ae4acb6c881e80b6348f9 the category parameter in search should result in a qualifier --- diff --git a/nominatim/api/search/db_search_builder.py b/nominatim/api/search/db_search_builder.py index 7826925a..35d10e78 100644 --- a/nominatim/api/search/db_search_builder.py +++ b/nominatim/api/search/db_search_builder.py @@ -321,8 +321,15 @@ class SearchBuilder: self.query.get_tokens(assignment.postcode, TokenType.POSTCODE)) if assignment.qualifier: - sdata.set_qualifiers(self.query.get_tokens(assignment.qualifier, - TokenType.QUALIFIER)) + tokens = self.query.get_tokens(assignment.qualifier, TokenType.QUALIFIER) + if self.details.categories: + tokens = [t for t in tokens if t.get_category() in self.details.categories] + if not tokens: + return None + sdata.set_qualifiers(tokens) + elif self.details.categories: + sdata.qualifiers = dbf.WeightedCategories(self.details.categories, + [0.0] * len(self.details.categories)) if assignment.address: sdata.set_ranking([self.get_addr_ranking(r) for r in assignment.address]) @@ -347,10 +354,6 @@ class SearchBuilder: tokens[cat] = t.penalty return dbf.WeightedCategories(list(tokens.keys()), list(tokens.values())) - if self.details.categories: - return dbf.WeightedCategories(self.details.categories, - [0.0] * len(self.details.categories)) - return None diff --git a/test/python/api/search/test_db_search_builder.py b/test/python/api/search/test_db_search_builder.py index c10a6c77..9d877b1d 100644 --- a/test/python/api/search/test_db_search_builder.py +++ b/test/python/api/search/test_db_search_builder.py @@ -309,8 +309,8 @@ def test_name_only_search_with_category(): assert len(searches) == 1 search = searches[0] - assert isinstance(search, dbs.NearSearch) - assert isinstance(search.search, dbs.PlaceSearch) + assert isinstance(search, dbs.PlaceSearch) + assert search.qualifiers.values == [('foo', 'bar')] def test_name_only_search_with_countries():