From: Sarah Hoffmann Date: Tue, 18 Mar 2025 21:32:58 +0000 (+0100) Subject: improve handling of leading postcodes X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/edc5ada625373010d7c2713209a943440f809b4f improve handling of leading postcodes Setting the direction of the query while yielding assignments is a bad idea because it may override a direction already set. --- diff --git a/src/nominatim_api/search/token_assignment.py b/src/nominatim_api/search/token_assignment.py index 3ca9385c..de75318a 100644 --- a/src/nominatim_api/search/token_assignment.py +++ b/src/nominatim_api/search/token_assignment.py @@ -269,10 +269,8 @@ class _TokenSequence: #
, should give preference to address search if base.postcode.start == 0: penalty = self.penalty - self.direction = -1 # name searches are only possible backwards else: penalty = self.penalty + 0.1 - self.direction = 1 # name searches are only possible forwards yield dataclasses.replace(base, penalty=penalty) def _get_assignments_address_forward(self, base: TokenAssignment, @@ -282,6 +280,11 @@ class _TokenSequence: """ first = base.address[0] + # The postcode must come after the name. + if base.postcode and base.postcode < first: + log().var_dump('skip forward', (base.postcode, first)) + return + log().comment('first word = name') yield dataclasses.replace(base, penalty=self.penalty, name=first, address=base.address[1:]) @@ -317,7 +320,12 @@ class _TokenSequence: """ last = base.address[-1] - if self.direction == -1 or len(base.address) > 1: + # The postcode must come before the name for backward direction. + if base.postcode and base.postcode > last: + log().var_dump('skip backward', (base.postcode, last)) + return + + if self.direction == -1 or len(base.address) > 1 or base.postcode: log().comment('last word = name') yield dataclasses.replace(base, penalty=self.penalty, name=last, address=base.address[:-1])