]> git.openstreetmap.org Git - nominatim.git/blobdiff - website/search.php
avoid warnings when geometry of object cannot be determined
[nominatim.git] / website / search.php
index afce2ee25da8d8ff87c0de3ef28f5bf4b190db09..7169c829abba66041c1d7a31c6940e418499be9c 100755 (executable)
                $aPhrases = array_reverse($aPhrases); 
                $sQuery = join(', ',$aPhrases);
        }
-
        if ($sQuery)
        {
                $hLog = logStart($oDB, 'search', $sQuery, $aLangPrefOrder);
                        $sQuery = preg_replace('/\\bil\\b/','illinois', $sQuery);
                        $sQuery = preg_replace('/\\bal\\b/','alabama', $sQuery);
                        $sQuery = preg_replace('/\\bla\\b/','louisiana', $sQuery);
+                       $sQuery = preg_replace('/\\bde louisiana\\b/','de la', $sQuery);
                }
 
                // If we have a view box create the SQL
                        $_GET['nearlon'] = ($aData[6]=='E'?1:-1) * ($aData[4] + $aData[5]/60);
                        $sQuery = trim(str_replace($aData[0], ' ', $sQuery));
                }
-               elseif (preg_match('/(\\[|\\b)(-?[0-9]+[0-9.]*)[, ]+(-?[0-9]+[0-9.]*)(\\]|\\b)/', $sQuery, $aData))
+               elseif (preg_match('/(\\[|^|\\b)(-?[0-9]+[0-9.]*)[, ]+(-?[0-9]+[0-9.]*)(\\]|$|\\b)/', $sQuery, $aData))
                {
                        $_GET['nearlat'] = $aData[2];
                        $_GET['nearlon'] = $aData[3];
                                                                        if ($bCacheTable)
                                                                        {
                                                                                // More efficient - can make the range bigger
-                                                                               $fRange = 0.05;
+                                                                               $fRange = 0.05;
+
+                                                                               $sOrderBySQL = '';
+                                                                               if ($sNearPointSQL) $sOrderBySQL = "ST_Distance($sNearPointSQL, l.centroid)";
+                                                                               else if ($sPlaceIDs) $sOrderBySQL = "ST_Distance(l.centroid, f.geometry)";
+                                                                               else if ($sPlaceGeom) $sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
                                                                                
-                                                                               $sSQL = "select distinct l.place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
+                                                                               $sSQL = "select distinct l.place_id".($sOrderBysSQL?','.$sOrderBysSQL:'')." from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
                                                                                if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)";
                                                                                if ($sPlaceIDs)
                                                                                {
                                                                                        $sSQL .= " and l.place_id not in (".join(',',$aExcludePlaceIDs).")";
                                                                                }
                                                                                if ($sCountryCodesSQL) $sSQL .= " and lp.country_code in ($sCountryCodesSQL)";
-                                                                               if ($sNearPointSQL) $sSQL .= " order by ST_Distance($sNearPointSQL, l.centroid) ASC";
-                                                                               else if ($sPlaceIDs) $sSQL .= " order by ST_Distance(l.centroid, f.geometry) asc";
-                                                                               else if ($sPlaceGeom) $sSQL .= " order by ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid) asc";
-                                                               
+                                                                               if ($sOrderBy) $sSQL .= "order by ".$OrderBysSQL." asc";
+                                                                               if ($iOffset) $sSQL .= " offset $iOffset";
                                                                                $sSQL .= " limit $iLimit";
                                                                                if (CONST_Debug) var_dump($sSQL);
                                                                                $aPlaceIDs = $oDB->getCol($sSQL);
                                                                        else
                                                                        {
                                                                                if (isset($aSearch['fRadius']) && $aSearch['fRadius']) $fRange = $aSearch['fRadius'];
-                                                                               $sSQL = "select distinct l.place_id from placex as l,placex as f where ";
+
+                                                                               $sOrderBySQL = '';
+                                                                               if ($sNearPointSQL) $sOrderBySQL = "ST_Distance($sNearPointSQL, l.geometry)";
+                                                                               else $sOrderBySQL = "ST_Distance(l.geometry, f.geometry)";
+
+                                                                               $sSQL = "select distinct l.place_id".($sOrderBysSQL?','.$sOrderBysSQL:'')." from placex as l,placex as f where ";
                                                                                $sSQL .= "f.place_id in ( $sPlaceIDs) and ST_DWithin(l.geometry, st_centroid(f.geometry), $fRange) ";
                                                                                $sSQL .= "and l.class='".$aSearch['sClass']."' and l.type='".$aSearch['sType']."' ";
                                                                                if (sizeof($aExcludePlaceIDs))
                                                                                        $sSQL .= " and l.place_id not in (".join(',',$aExcludePlaceIDs).")";
                                                                                }
                                                                                if ($sCountryCodesSQL) $sSQL .= " and l.country_code in ($sCountryCodesSQL)";                                                           
-                                                                               if ($sNearPointSQL) $sSQL .= " order by ST_Distance($sNearPointSQL, l.geometry) ASC";
-                                                                               else $sSQL .= " order by ST_Distance(l.geometry, f.geometry) asc, l.rank_search ASC";
+                                                                               if ($sOrderBy) $sSQL .= "order by ".$OrderBysSQL." asc";
+                                                                               if ($iOffset) $sSQL .= " offset $iOffset";
                                                                                $sSQL .= " limit $iLimit";
                                                                                if (CONST_Debug) var_dump($sSQL);
                                                                                $aPlaceIDs = $oDB->getCol($sSQL);
                                }
 
                                // Output data suitable for display (points and a bounding box)
-                               if ($bShowPolygons)
+                               if ($bShowPolygons && isset($aPolyPoints))
                                {
                                        $aResult['aPolyPoints'] = array();
                                        foreach($aPolyPoints as $aPoint)