]> git.openstreetmap.org Git - nominatim.git/commitdiff
disallow category tokens in the middle of a query string
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 28 Jan 2024 10:35:30 +0000 (11:35 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 28 Jan 2024 18:03:11 +0000 (19:03 +0100)
This already worked for left-to-right readings and now is also
implemented for right-to-left reading. A qualifier must always be
before or after the name.

nominatim/api/search/token_assignment.py
test/python/api/search/test_token_assignment.py

index d94d69039f0f602ab8c0aeda9e5c971a881353fd..b874dcd761a1a31d127baf9e7e0259af6cacfae9 100644 (file)
@@ -132,6 +132,11 @@ class _TokenSequence:
 
         # Name tokens are always acceptable and don't change direction
         if ttype == qmod.TokenType.PARTIAL:
+            # qualifiers cannot appear in the middle of the qeury. They need
+            # to be near the next phrase.
+            if self.direction == -1 \
+               and any(t.ttype == qmod.TokenType.QUALIFIER for t in self.seq[:-1]):
+                return None
             return self.direction
 
         # Other tokens may only appear once
index 2ed55a0f80afb06372ef27f6a49fcf840e3854cc..54e8af14cc27fb466e58a99a5d3d7ef28657e1f6 100644 (file)
@@ -337,3 +337,14 @@ def test_qualifier_after_housenumber():
                    (BreakType.WORD, PhraseType.NONE, [(3, TokenType.PARTIAL)]))
 
     check_assignments(yield_token_assignments(q))
+
+
+def test_qualifier_in_middle_of_phrase():
+    q = make_query((BreakType.START, PhraseType.NONE, [(1, TokenType.PARTIAL)]),
+                   (BreakType.PHRASE, PhraseType.NONE, [(2, TokenType.PARTIAL)]),
+                   (BreakType.WORD, PhraseType.NONE, [(3, TokenType.QUALIFIER)]),
+                   (BreakType.WORD, PhraseType.NONE, [(4, TokenType.PARTIAL)]),
+                   (BreakType.PHRASE, PhraseType.NONE, [(5, TokenType.PARTIAL)]))
+
+    check_assignments(yield_token_assignments(q))
+