Skip to content

Commit

Permalink
Merge pull request #3128 from lonvia/fix-classtype-lookup
Browse files Browse the repository at this point in the history
Fix query over classtype tables
  • Loading branch information
lonvia authored Jul 31, 2023
2 parents d97ca9f + 8fc3dd9 commit c29ffc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions nominatim/api/search/db_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,11 @@ async def lookup_category(self, results: nres.SearchResults,
# radius for the lookup.
sql = sql.join(table, t.c.place_id == table.c.place_id)\
.join(tgeom,
sa.case((sa.and_(tgeom.c.rank_address < 9,
tgeom.c.geometry.is_area()),
tgeom.c.geometry.ST_Contains(table.c.centroid)),
else_ = tgeom.c.centroid.ST_DWithin(table.c.centroid, 0.05)))\
table.c.centroid.ST_CoveredBy(
sa.case((sa.and_(tgeom.c.rank_address < 9,
tgeom.c.geometry.is_area()),
tgeom.c.geometry),
else_ = tgeom.c.centroid.ST_Expand(0.05))))\
.order_by(tgeom.c.centroid.ST_Distance(table.c.centroid))

sql = sql.where(t.c.rank_address.between(MIN_RANK_PARAM, MAX_RANK_PARAM))
Expand Down
6 changes: 5 additions & 1 deletion nominatim/db/sqlalchemy_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def ST_Distance(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:
Expand Down

0 comments on commit c29ffc3

Please sign in to comment.