From 283db76e458c3159888f01e5837ff8db0bfd9780 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 14 Jul 2023 21:05:13 +0200 Subject: [PATCH] avoid splitting of first token when a housenumber is present This only covers the case of which is exceedingly rare. --- nominatim/api/search/db_search_builder.py | 2 -- nominatim/api/search/token_assignment.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nominatim/api/search/db_search_builder.py b/nominatim/api/search/db_search_builder.py index 794012b0..d18fa964 100644 --- a/nominatim/api/search/db_search_builder.py +++ b/nominatim/api/search/db_search_builder.py @@ -225,9 +225,7 @@ class SearchBuilder: # This might yield wrong results, nothing we can do about that. if not partials_indexed: addr_tokens = [t.token for t in addr_partials if t.is_indexed] - log().var_dump('before', penalty) penalty += 1.2 * sum(t.penalty for t in addr_partials if not t.is_indexed) - log().var_dump('after', penalty) if rare_names: # Any of the full names applies with all of the partials from the address lookup = [dbf.FieldLookup('name_vector', [t.token for t in rare_names], 'lookup_any')] diff --git a/nominatim/api/search/token_assignment.py b/nominatim/api/search/token_assignment.py index 11da2359..f1c2f8e8 100644 --- a/nominatim/api/search/token_assignment.py +++ b/nominatim/api/search/token_assignment.py @@ -309,9 +309,12 @@ class _TokenSequence: first = base.address[0] if (not base.housenumber or first.end >= base.housenumber.start)\ and (not base.qualifier or first.start >= base.qualifier.end): + base_penalty = self.penalty + if base.housenumber and base.housenumber.start > first.start: + base_penalty += 0.25 for i in range(first.start + 1, first.end): name, addr = first.split(i) - penalty = self.penalty + PENALTY_TOKENCHANGE[query.nodes[i].btype] + penalty = base_penalty + PENALTY_TOKENCHANGE[query.nodes[i].btype] log().comment(f'split first word = name ({i - first.start})') yield dataclasses.replace(base, name=name, penalty=penalty, address=[addr] + base.address[1:]) @@ -321,9 +324,12 @@ class _TokenSequence: last = base.address[-1] if (not base.housenumber or last.start <= base.housenumber.end)\ and (not base.qualifier or last.end <= base.qualifier.start): + base_penalty = self.penalty + if base.housenumber and base.housenumber.start < last.start: + base_penalty += 0.4 for i in range(last.start + 1, last.end): addr, name = last.split(i) - penalty = self.penalty + PENALTY_TOKENCHANGE[query.nodes[i].btype] + penalty = base_penalty + PENALTY_TOKENCHANGE[query.nodes[i].btype] log().comment(f'split last word = name ({i - last.start})') yield dataclasses.replace(base, name=name, penalty=penalty, address=base.address[:-1] + [addr]) -- 2.39.5