mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
fix query over classtype tables
The case statement prevented the index on the classtype tables from being used. Move the case statement inside the geometry function instead.
This commit is contained in:
@@ -287,10 +287,11 @@ class NearSearch(AbstractSearch):
|
|||||||
# radius for the lookup.
|
# radius for the lookup.
|
||||||
sql = sql.join(table, t.c.place_id == table.c.place_id)\
|
sql = sql.join(table, t.c.place_id == table.c.place_id)\
|
||||||
.join(tgeom,
|
.join(tgeom,
|
||||||
sa.case((sa.and_(tgeom.c.rank_address < 9,
|
table.c.centroid.ST_CoveredBy(
|
||||||
tgeom.c.geometry.is_area()),
|
sa.case((sa.and_(tgeom.c.rank_address < 9,
|
||||||
tgeom.c.geometry.ST_Contains(table.c.centroid)),
|
tgeom.c.geometry.is_area()),
|
||||||
else_ = tgeom.c.centroid.ST_DWithin(table.c.centroid, 0.05)))\
|
tgeom.c.geometry),
|
||||||
|
else_ = tgeom.c.centroid.ST_Expand(0.05))))\
|
||||||
.order_by(tgeom.c.centroid.ST_Distance(table.c.centroid))
|
.order_by(tgeom.c.centroid.ST_Distance(table.c.centroid))
|
||||||
|
|
||||||
sql = sql.where(t.c.rank_address.between(MIN_RANK_PARAM, MAX_RANK_PARAM))
|
sql = sql.where(t.c.rank_address.between(MIN_RANK_PARAM, MAX_RANK_PARAM))
|
||||||
|
|||||||
@@ -74,7 +74,11 @@ class Geometry(types.UserDefinedType): # type: ignore[type-arg]
|
|||||||
|
|
||||||
|
|
||||||
def ST_Contains(self, other: SaColumn) -> SaColumn:
|
def ST_Contains(self, other: SaColumn) -> SaColumn:
|
||||||
return sa.func.ST_Contains(self, other, type_=sa.Float)
|
return sa.func.ST_Contains(self, other, type_=sa.Boolean)
|
||||||
|
|
||||||
|
|
||||||
|
def ST_CoveredBy(self, other: SaColumn) -> SaColumn:
|
||||||
|
return sa.func.ST_CoveredBy(self, other, type_=sa.Boolean)
|
||||||
|
|
||||||
|
|
||||||
def ST_ClosestPoint(self, other: SaColumn) -> SaColumn:
|
def ST_ClosestPoint(self, other: SaColumn) -> SaColumn:
|
||||||
|
|||||||
Reference in New Issue
Block a user