]> git.openstreetmap.org Git - nominatim.git/commitdiff
the category parameter in search should result in a qualifier
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 28 Nov 2023 11:01:49 +0000 (12:01 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 28 Nov 2023 11:01:49 +0000 (12:01 +0100)
nominatim/api/search/db_search_builder.py
test/python/api/search/test_db_search_builder.py

index 7826925aed6ce77271e92bbef4612a3b1e5357bd..35d10e782e3d19026de775270c329c4db8dddb2b 100644 (file)
@@ -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
 
 
index c10a6c77f2917828b1ca4007f36789db5881b1e6..9d877b1db9ee5aa575f8c508cf94d25db5f8ffbf 100644 (file)
@@ -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():