From 0c72a434e033c54729294129dd4e37527db19faf Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 25 Nov 2023 18:39:28 +0100 Subject: [PATCH] use restrict for housenumber lookups with few numbers --- nominatim/api/search/db_search_builder.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nominatim/api/search/db_search_builder.py b/nominatim/api/search/db_search_builder.py index 6d94feab..39c25f6b 100644 --- a/nominatim/api/search/db_search_builder.py +++ b/nominatim/api/search/db_search_builder.py @@ -163,11 +163,15 @@ class SearchBuilder: housenumber is the main name token. """ sdata.lookups = [dbf.FieldLookup('name_vector', [t.token for t in hnrs], 'lookup_any')] + expected_count = sum(t.count for t in hnrs) partials = [t for trange in address for t in self.query.get_partials_list(trange)] - if len(partials) != 1 or partials[0].count < 10000: + if expected_count < 8000: + sdata.lookups.append(dbf.FieldLookup('nameaddress_vector', + [t.token for t in partials], 'restrict')) + elif len(partials) != 1 or partials[0].count < 10000: sdata.lookups.append(dbf.FieldLookup('nameaddress_vector', [t.token for t in partials], 'lookup_all')) else: @@ -178,7 +182,7 @@ class SearchBuilder: 'lookup_any')) sdata.housenumbers = dbf.WeightedStrings([], []) - yield dbs.PlaceSearch(0.05, sdata, sum(t.count for t in hnrs)) + yield dbs.PlaceSearch(0.05, sdata, expected_count) def build_name_search(self, sdata: dbf.SearchData, -- 2.39.5