]> git.openstreetmap.org Git - nominatim.git/commitdiff
use word_token length when penalizing against postcodes
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 18 Mar 2025 22:07:27 +0000 (23:07 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 19 Mar 2025 08:52:40 +0000 (09:52 +0100)
src/nominatim_api/search/icu_tokenizer.py

index b6cd34646f4029a619d1cfa1ef262f015fab04b4..1bd0030d54f0319581c22dd5921c2deeaa8f0927 100644 (file)
@@ -269,10 +269,10 @@ class ICUQueryAnalyzer(AbstractQueryAnalyzer):
         """
         for i, node, tlist in query.iter_token_lists():
             if tlist.ttype == qmod.TOKEN_POSTCODE:
+                tlen = len(cast(ICUToken, tlist.tokens[0]).word_token)
                 for repl in node.starting:
                     if repl.end == tlist.end and repl.ttype != qmod.TOKEN_POSTCODE \
-                       and (repl.ttype != qmod.TOKEN_HOUSENUMBER
-                            or len(tlist.tokens[0].lookup_word) > 4):
+                       and (repl.ttype != qmod.TOKEN_HOUSENUMBER or tlen > 4):
                         repl.add_penalty(0.39)
             elif (tlist.ttype == qmod.TOKEN_HOUSENUMBER
                   and len(tlist.tokens[0].lookup_word) <= 3):