limit number of considered places in POI queries

When searching for POIs in place_classtype_ tables limit the number
of objects considered to 300. The distinct and order by clauses
forced until now to retrive all matching objects and order them
first which can cause long running queries when retriving them
for large areas like the US.

Fixes #735.
This commit is contained in:
Sarah Hoffmann
2017-06-05 21:33:50 +02:00
parent 13674c3939
commit c13094acfd
2 changed files with 7 additions and 4 deletions

View File

@@ -1555,8 +1555,9 @@ class Geocode
} }
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'near') { // & in if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'near') { // & in
$sClassTable = 'place_classtype_'.$aSearch['sClass'].'_'.$aSearch['sType'];
$sSQL = "SELECT count(*) FROM pg_tables "; $sSQL = "SELECT count(*) FROM pg_tables ";
$sSQL .= "WHERE tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'"; $sSQL .= "WHERE tablename = '$sClassTable'";
$bCacheTable = chksql($this->oDB->getOne($sSQL)); $bCacheTable = chksql($this->oDB->getOne($sSQL));
$sSQL = "SELECT min(rank_search) FROM placex WHERE place_id in ($sPlaceIDs)"; $sSQL = "SELECT min(rank_search) FROM placex WHERE place_id in ($sPlaceIDs)";
@@ -1604,7 +1605,8 @@ class Geocode
$sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)"; $sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
} }
$sSQL = "select distinct l.place_id".($sOrderBySQL?','.$sOrderBySQL:'')." from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l"; $sSQL = "select distinct i.place_id".($sOrderBySQL?', i.order_term':'')." from (";
$sSQL .= "select l.place_id".($sOrderBySQL?','.$sOrderBySQL.' as order_term':'')." from ".$sClassTable." as l";
if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)"; if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)";
if ($sPlaceIDs) { if ($sPlaceIDs) {
$sSQL .= ",placex as f where "; $sSQL .= ",placex as f where ";
@@ -1618,7 +1620,8 @@ class Geocode
$sSQL .= " and l.place_id not in (".join(',', $this->aExcludePlaceIDs).")"; $sSQL .= " and l.place_id not in (".join(',', $this->aExcludePlaceIDs).")";
} }
if ($sCountryCodesSQL) $sSQL .= " and lp.country_code in ($sCountryCodesSQL)"; if ($sCountryCodesSQL) $sSQL .= " and lp.country_code in ($sCountryCodesSQL)";
if ($sOrderBySQL) $sSQL .= "order by ".$sOrderBySQL." asc"; $sSQL .= 'limit 300) i ';
if ($sOrderBySQL) $sSQL .= "order by order_term asc";
if ($this->iOffset) $sSQL .= " offset $this->iOffset"; if ($this->iOffset) $sSQL .= " offset $this->iOffset";
$sSQL .= " limit $this->iLimit"; $sSQL .= " limit $this->iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);

View File

@@ -52,7 +52,7 @@ Feature: Search queries
| way | | way |
Scenario: Search with class-type feature Scenario: Search with class-type feature
When sending jsonv2 search query "Hotel California" When sending jsonv2 search query "Hotel in California"
Then results contain Then results contain
| place_rank | | place_rank |
| 30 | | 30 |