X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/dc99bbb0afb7632b5497d4f6f41acff5b2e635e2..7d911f9ffbdf63b2b2a45c3a3ee7063d006a5779:/nominatim/api/search/db_searches.py diff --git a/nominatim/api/search/db_searches.py b/nominatim/api/search/db_searches.py index 9a94b4f6..76ff368f 100644 --- a/nominatim/api/search/db_searches.py +++ b/nominatim/api/search/db_searches.py @@ -20,7 +20,7 @@ from nominatim.api.types import SearchDetails, DataLayer, GeometryFormat, Bbox import nominatim.api.results as nres from nominatim.api.search.db_search_fields import SearchData, WeightedCategories -#pylint: disable=singleton-comparison +#pylint: disable=singleton-comparison,not-callable #pylint: disable=too-many-branches,too-many-arguments,too-many-locals,too-many-statements def _select_placex(t: SaFromClause) -> SaSelect: @@ -403,6 +403,12 @@ class CountrySearch(AbstractSearch): details: SearchDetails) -> nres.SearchResults: """ Look up the country in the fallback country tables. """ + # Avoid the fallback search when this is a more search. Country results + # usually are in the first batch of results and it is not possible + # to exclude these fallbacks. + if details.excluded: + return nres.SearchResults() + t = conn.t.country_name tgrid = conn.t.country_grid @@ -562,6 +568,8 @@ class PlaceSearch(AbstractSearch): sql = sql.where(tsearch.c.country_code.in_(self.countries.values)) if self.postcodes: + # if a postcode is given, don't search for state or country level objects + sql = sql.where(tsearch.c.address_rank > 9) tpc = conn.t.postcode if self.expected_count > 1000: # Many results expected. Restrict by postcode. @@ -639,8 +647,8 @@ class PlaceSearch(AbstractSearch): numerals, details) ), else_=None) else: - interpol_sql = sa.literal(None) - tiger_sql = sa.literal(None) + interpol_sql = sa.literal_column('NULL') + tiger_sql = sa.literal_column('NULL') unsort = sa.select(inner, place_sql.scalar_subquery().label('placex_hnr'), interpol_sql.label('interpol_hnr'),