From f2236f68f18c3084b8a5810dd3cfe7d642a2b51d Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 1 Jun 2025 11:53:23 +0200 Subject: [PATCH] when rematching only distinguish between perfect, somewhat and bad match --- src/nominatim_api/search/geocoder.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/nominatim_api/search/geocoder.py b/src/nominatim_api/search/geocoder.py index 5fefe5ea..dfc6bc52 100644 --- a/src/nominatim_api/search/geocoder.py +++ b/src/nominatim_api/search/geocoder.py @@ -153,11 +153,10 @@ class ForwardGeocoder: if not words: continue for qword in qwords: - wdist = max(difflib.SequenceMatcher(a=qword, b=w).quick_ratio() for w in words) - if wdist < 0.5: - distance += len(qword) - else: - distance += (1.0 - wdist) * len(qword) + # only add distance penalty if there is no perfect match + if qword not in words: + wdist = max(difflib.SequenceMatcher(a=qword, b=w).quick_ratio() for w in words) + distance += len(qword) if wdist < 0.4 else 1 # Compensate for the fact that country names do not get a # match penalty yet by the tokenizer. # Temporary hack that needs to be removed! -- 2.39.5