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.
This commit is contained in:
Sarah Hoffmann
2025-03-18 22:32:58 +01:00
parent 72d3360fa2
commit edc5ada625

View File

@@ -269,10 +269,8 @@ class _TokenSequence:
# <address>,<postcode> 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])