]> git.openstreetmap.org Git - nominatim.git/commitdiff
interpret stand-alone special terms always as near term
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Jan 2024 16:19:21 +0000 (17:19 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Jan 2024 16:19:21 +0000 (17:19 +0100)
Fixes #3298.

nominatim/api/search/icu_tokenizer.py
test/bdd/api/search/queries.feature
test/python/api/search/test_icu_query_analyzer.py

index 72e0f547bcbaf9f5bb0798b8d26ce8b228b22249..1c2565d1ad60c80df1f1ecb78b216439b8d98224 100644 (file)
@@ -186,7 +186,10 @@ class ICUQueryAnalyzer(AbstractQueryAnalyzer):
                         if trange.start == 0:
                             query.add_token(trange, qmod.TokenType.NEAR_ITEM, token)
                     else:
-                        query.add_token(trange, qmod.TokenType.QUALIFIER, token)
+                        if trange.start == 0 and trange.end == query.num_token_slots():
+                            query.add_token(trange, qmod.TokenType.NEAR_ITEM, token)
+                        else:
+                            query.add_token(trange, qmod.TokenType.QUALIFIER, token)
                 else:
                     query.add_token(trange, DB_TO_TOKEN_TYPE[row.type], token)
 
index eba903ea3058ecee883778cd96f609f99766b6cc..b2793faa3a3696dc0fd9bcf5ea497276e70b1c72 100644 (file)
@@ -136,6 +136,15 @@ Feature: Search queries
           | class    | type |
           | leisure | firepit |
 
+
+    Scenario: POI search in a bounded viewbox
+        When sending json search query "restaurants"
+          | viewbox                           | bounded |
+          | 9.50830,47.15253,9.52043,47.14866 | 1 |
+        Then results contain
+          | class   | type       |
+          | amenity | restaurant |
+
     Scenario Outline: Key/value search near given coordinate can be restricted to country
         When sending json search query "[natural=peak] 47.06512,9.53965" with address
           | countrycodes |
index 6a17e32abab37475d8ab5178d2a5ee5fc2fffe1e..2ec3a7fecc85715536241b9b7d6c25c056427cd2 100644 (file)
@@ -138,6 +138,19 @@ async def test_category_words_only_at_beginning(conn):
     assert not query.nodes[2].starting
 
 
+@pytest.mark.asyncio
+async def test_freestanding_qualifier_words_become_category(conn):
+    ana = await tok.create_query_analyzer(conn)
+
+    await add_word(conn, 1, 'foo', 'S', 'FOO', {'op': '-'})
+
+    query = await ana.analyze_query(make_phrase('foo'))
+
+    assert query.num_token_slots() == 1
+    assert len(query.nodes[0].starting) == 1
+    assert query.nodes[0].starting[0].ttype == TokenType.NEAR_ITEM
+
+
 @pytest.mark.asyncio
 async def test_qualifier_words(conn):
     ana = await tok.create_query_analyzer(conn)