mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-09 19:44:07 +00:00
streamline selected columns in search CTEs
This commit is contained in:
@@ -155,10 +155,7 @@ class AddressSearch(base.AbstractSearch):
|
|||||||
for ranking in self.rankings:
|
for ranking in self.rankings:
|
||||||
penalty += ranking.sql_penalty(t)
|
penalty += ranking.sql_penalty(t)
|
||||||
|
|
||||||
sql = sa.select(t.c.place_id, t.c.address_rank,
|
sql = sa.select(t.c.place_id, penalty.label('penalty'))
|
||||||
t.c.country_code, t.c.centroid,
|
|
||||||
t.c.name_vector, t.c.nameaddress_vector,
|
|
||||||
t.c.importance, penalty.label('penalty'))
|
|
||||||
|
|
||||||
for lookup in self.lookups:
|
for lookup in self.lookups:
|
||||||
sql = sql.where(lookup.sql_condition(t))
|
sql = sql.where(lookup.sql_condition(t))
|
||||||
@@ -199,9 +196,7 @@ class AddressSearch(base.AbstractSearch):
|
|||||||
|
|
||||||
inner = sql.limit(10000).order_by(sa.desc(sa.text('importance'))).subquery()
|
inner = sql.limit(10000).order_by(sa.desc(sa.text('importance'))).subquery()
|
||||||
|
|
||||||
sql = sa.select(inner.c.place_id, inner.c.address_rank,
|
sql = sa.select(inner.c.place_id, inner.c.penalty)
|
||||||
inner.c.country_code, inner.c.centroid, inner.c.importance,
|
|
||||||
inner.c.penalty)
|
|
||||||
|
|
||||||
return sql.cte('searches')
|
return sql.cte('searches')
|
||||||
|
|
||||||
@@ -237,12 +232,12 @@ class AddressSearch(base.AbstractSearch):
|
|||||||
else_=1.0)
|
else_=1.0)
|
||||||
|
|
||||||
if details.near is not None:
|
if details.near is not None:
|
||||||
sql = sql.add_columns((-tsearch.c.centroid.ST_Distance(NEAR_PARAM))
|
sql = sql.add_columns((-t.c.centroid.ST_Distance(NEAR_PARAM))
|
||||||
.label('importance'))
|
.label('importance'))
|
||||||
sql = sql.order_by(sa.desc(sa.text('importance')))
|
sql = sql.order_by(sa.desc(sa.text('importance')))
|
||||||
else:
|
else:
|
||||||
sql = sql.order_by(penalty - tsearch.c.importance)
|
sql = sql.order_by(penalty - t.c.importance)
|
||||||
sql = sql.add_columns(tsearch.c.importance)
|
sql = sql.add_columns(t.c.importance)
|
||||||
|
|
||||||
sql = sql.add_columns(penalty.label('accuracy'))\
|
sql = sql.add_columns(penalty.label('accuracy'))\
|
||||||
.order_by(sa.text('accuracy'))
|
.order_by(sa.text('accuracy'))
|
||||||
@@ -250,7 +245,7 @@ class AddressSearch(base.AbstractSearch):
|
|||||||
hnr_list = '|'.join(self.housenumbers.values)
|
hnr_list = '|'.join(self.housenumbers.values)
|
||||||
|
|
||||||
if self.has_address_terms:
|
if self.has_address_terms:
|
||||||
sql = sql.where(sa.or_(tsearch.c.address_rank < 30,
|
sql = sql.where(sa.or_(t.c.rank_address < 30,
|
||||||
sa.func.RegexpWord(hnr_list, t.c.housenumber)))
|
sa.func.RegexpWord(hnr_list, t.c.housenumber)))
|
||||||
|
|
||||||
inner = sql.subquery()
|
inner = sql.subquery()
|
||||||
|
|||||||
@@ -58,10 +58,7 @@ class PlaceSearch(base.AbstractSearch):
|
|||||||
for ranking in self.rankings:
|
for ranking in self.rankings:
|
||||||
penalty += ranking.sql_penalty(t)
|
penalty += ranking.sql_penalty(t)
|
||||||
|
|
||||||
sql = sa.select(t.c.place_id, t.c.address_rank,
|
sql = sa.select(t.c.place_id, t.c.importance)
|
||||||
t.c.country_code, t.c.centroid,
|
|
||||||
t.c.name_vector, t.c.nameaddress_vector,
|
|
||||||
t.c.importance)
|
|
||||||
|
|
||||||
for lookup in self.lookups:
|
for lookup in self.lookups:
|
||||||
sql = sql.where(lookup.sql_condition(t))
|
sql = sql.where(lookup.sql_condition(t))
|
||||||
@@ -115,11 +112,9 @@ class PlaceSearch(base.AbstractSearch):
|
|||||||
.order_by(sa.desc(sa.text('importance')))\
|
.order_by(sa.desc(sa.text('importance')))\
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
sql = sa.select(inner.c.place_id, inner.c.address_rank,
|
sql = sa.select(inner.c.place_id, inner.c.importance, inner.c.penalty)
|
||||||
inner.c.country_code, inner.c.centroid, inner.c.importance,
|
|
||||||
inner.c.penalty)
|
|
||||||
|
|
||||||
# If the query is not an address search or has a geographic preference,
|
# If the query has no geographic preference,
|
||||||
# preselect most important items to restrict the number of places
|
# preselect most important items to restrict the number of places
|
||||||
# that need to be looked up in placex.
|
# that need to be looked up in placex.
|
||||||
if (details.viewbox is None or not details.bounded_viewbox)\
|
if (details.viewbox is None or not details.bounded_viewbox)\
|
||||||
@@ -131,9 +126,7 @@ class PlaceSearch(base.AbstractSearch):
|
|||||||
|
|
||||||
inner = sql.subquery()
|
inner = sql.subquery()
|
||||||
|
|
||||||
sql = sa.select(inner.c.place_id, inner.c.address_rank,
|
sql = sa.select(inner.c.place_id, inner.c.penalty)\
|
||||||
inner.c.country_code, inner.c.centroid, inner.c.importance,
|
|
||||||
inner.c.penalty)\
|
|
||||||
.where(inner.c.penalty - inner.c.importance < inner.c.min_penalty + 0.5)
|
.where(inner.c.penalty - inner.c.importance < inner.c.min_penalty + 0.5)
|
||||||
|
|
||||||
return sql.cte('searches')
|
return sql.cte('searches')
|
||||||
@@ -168,12 +161,12 @@ class PlaceSearch(base.AbstractSearch):
|
|||||||
penalty += sa.case((t.c.postcode.in_(self.postcodes.values), 0.0), else_=1.0)
|
penalty += sa.case((t.c.postcode.in_(self.postcodes.values), 0.0), else_=1.0)
|
||||||
|
|
||||||
if details.near is not None:
|
if details.near is not None:
|
||||||
sql = sql.add_columns((-tsearch.c.centroid.ST_Distance(NEAR_PARAM))
|
sql = sql.add_columns((-t.c.centroid.ST_Distance(NEAR_PARAM))
|
||||||
.label('importance'))
|
.label('importance'))
|
||||||
sql = sql.order_by(sa.desc(sa.text('importance')))
|
sql = sql.order_by(sa.desc(sa.text('importance')))
|
||||||
else:
|
else:
|
||||||
sql = sql.order_by(penalty - tsearch.c.importance)
|
sql = sql.order_by(penalty - t.c.importance)
|
||||||
sql = sql.add_columns(tsearch.c.importance)
|
sql = sql.add_columns(t.c.importance)
|
||||||
|
|
||||||
if details.min_rank > 0:
|
if details.min_rank > 0:
|
||||||
sql = sql.where(sa.or_(t.c.rank_address >= MIN_RANK_PARAM,
|
sql = sql.where(sa.or_(t.c.rank_address >= MIN_RANK_PARAM,
|
||||||
|
|||||||
Reference in New Issue
Block a user