1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2023 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Custom functions and expressions for SQLAlchemy.
 
  11 import sqlalchemy as sa
 
  13 def select_index_placex_geometry_reverse_lookuppolygon(table: str) -> 'sa.TextClause':
 
  14     """ Create an expression with the necessary conditions over a placex
 
  15         table that the index 'idx_placex_geometry_reverse_lookupPolygon'
 
  18     return sa.text(f"ST_GeometryType({table}.geometry) in ('ST_Polygon', 'ST_MultiPolygon')"
 
  19                    f" AND {table}.rank_address between 4 and 25"
 
  20                    f" AND {table}.type != 'postcode'"
 
  21                    f" AND {table}.name is not null"
 
  22                    f" AND {table}.indexed_status = 0"
 
  23                    f" AND {table}.linked_place_id is null")
 
  25 def select_index_placex_geometry_reverse_lookupplacenode(table: str) -> 'sa.TextClause':
 
  26     """ Create an expression with the necessary conditions over a placex
 
  27         table that the index 'idx_placex_geometry_reverse_lookupPlaceNode'
 
  30     return sa.text(f"{table}.rank_address between 4 and 25"
 
  31                    f" AND {table}.type != 'postcode'"
 
  32                    f" AND {table}.name is not null"
 
  33                    f" AND {table}.linked_place_id is null"
 
  34                    f" AND {table}.osm_type = 'N'")