From 55d3f5a4b96ecb69d22c15a6f78ea09c73cfd2ed Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 25 Aug 2012 01:09:52 +0200 Subject: [PATCH] fix 500 on search for bounded and class query terms Ignore bounded=1 if no viewbox parameter was given. New centroid column in placex makes it necessary to name the table when joining with classtype tables. --- website/search.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/website/search.php b/website/search.php index 5e2ff371..77892f23 100755 --- a/website/search.php +++ b/website/search.php @@ -133,6 +133,8 @@ $aCoOrdinates[1] += $fWidth; $aCoOrdinates[3] -= $fWidth; $sViewboxLargeSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$aCoOrdinates[0].",".(float)$aCoOrdinates[1]."),ST_Point(".(float)$aCoOrdinates[2].",".(float)$aCoOrdinates[3].")),4326)"; + } else { + $bBoundingBoxSearch = false; } if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth']) { @@ -703,22 +705,22 @@ $sSQL = "select count(*) from pg_tables where tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'"; if ($oDB->getOne($sSQL)) { - $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']; + $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." ct"; if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)"; - $sSQL .= " where st_contains($sViewboxSmallSQL, centroid)"; + $sSQL .= " where st_contains($sViewboxSmallSQL, ct.centroid)"; if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)"; - if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, centroid) asc"; + if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, ct.centroid) asc"; $sSQL .= " limit $iLimit"; if (CONST_Debug) var_dump($sSQL); $aPlaceIDs = $oDB->getCol($sSQL); if (!sizeof($aPlaceIDs)) { - $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']; + $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." ct"; if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)"; - $sSQL .= " where st_contains($sViewboxLargeSQL, centroid)"; + $sSQL .= " where st_contains($sViewboxLargeSQL, ct.centroid)"; if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)"; - if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, centroid) asc"; + if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, ct.centroid) asc"; $sSQL .= " limit $iLimit"; if (CONST_Debug) var_dump($sSQL); $aPlaceIDs = $oDB->getCol($sSQL);