X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/85ab12c4716ce96f4d666fcc0bd59fa32d68874e..932d945b7f897fd18be7d4c2fac3eda3915aa296:/website/search.php diff --git a/website/search.php b/website/search.php index a1d0db72..cc73513e 100755 --- a/website/search.php +++ b/website/search.php @@ -36,8 +36,8 @@ // Show address breakdown $bShowAddressDetails = isset($_GET['addressdetails']) && $_GET['addressdetails']; - // Prefered language - $aLangPrefOrder = getPrefferedLangauges(); + // Preferred language + $aLangPrefOrder = getPreferredLanguages(); if (isset($aLangPrefOrder['name:de'])) $bReverseInPlan = true; if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true; if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true; @@ -53,7 +53,7 @@ } } - // Only certain ranks of feature + // Only certain ranks of feature if (isset($_GET['featureType']) && !isset($_GET['featuretype'])) $_GET['featuretype'] = $_GET['featureType']; if (isset($_GET['featuretype'])) @@ -92,11 +92,11 @@ // Search query $sQuery = (isset($_GET['q'])?trim($_GET['q']):''); - if (!$sQuery && $_SERVER['PATH_INFO'] && $_SERVER['PATH_INFO'][0] == '/') + if (!$sQuery && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') { $sQuery = substr($_SERVER['PATH_INFO'], 1); - // reverse order of '/' seperated string + // reverse order of '/' separated string $aPhrases = explode('/', $sQuery); $aPhrases = array_reverse($aPhrases); $sQuery = join(', ',$aPhrases); @@ -109,10 +109,9 @@ $sQuery = str_ireplace(array('New York, ny','new york, new york', 'New York ny','new york new york'), 'new york city, ny', $sQuery); if (isset($aLangPrefOrder['name:en'])) { - $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); + $sQuery = preg_replace('/,\s*il\s*(,|$)/',', illinois\1', $sQuery); + $sQuery = preg_replace('/,\s*al\s*(,|$)/',', alabama\1', $sQuery); + $sQuery = preg_replace('/,\s*la\s*(,|$)/',', louisiana\1', $sQuery); } // If we have a view box create the SQL @@ -311,7 +310,12 @@ // Check which tokens we have, get the ID numbers $sSQL = 'select word_id,word_token, word, class, type, location, country_code, operator'; $sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')'; - $sSQL .= ' and (class is null or class not in (\'highway\'))'; + // HACK WARNING + // (mis)using search_name_count to exclude words that return too many + // search results. saerch_name_count is currently set to 1 by hand + // because there is no fast way to extract this count from a live database. + $sSQL .= ' and search_name_count = 0'; +// $sSQL .= ' and (class is null or class not in (\'highway\'))'; // $sSQL .= ' group by word_token, word, class, type, location, country_code'; if (CONST_Debug) var_Dump($sSQL); @@ -447,12 +451,12 @@ if ($aSearch['sCountryCode'] === false) { $aSearch['sCountryCode'] = strtolower($aSearchTerm['country_code']); - // Country is almost always at the end of the string - increase score for finding it anywhere else (opimisation) + // Country is almost always at the end of the string - increase score for finding it anywhere else (optimisation) if ($iWordset+1 != sizeof($aPhrases[$iPhrase]['wordsets']) || $iPhrase+1 != sizeof($aPhrases)) $aSearch['iSearchRank'] += 5; if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch; } } - elseif ($aSearchTerm['lat'] !== '' && $aSearchTerm['lat'] !== null) + elseif (isset($aSearchTerm['lat']) && $aSearchTerm['lat'] !== '' && $aSearchTerm['lat'] !== null) { if ($aSearch['fLat'] === '') { @@ -790,11 +794,16 @@ $sSQL .= " limit ".$iLimit; if (CONST_Debug) var_dump($sSQL); + $iStartTime = time(); $aViewBoxPlaceIDs = $oDB->getAll($sSQL); if (PEAR::IsError($aViewBoxPlaceIDs)) { failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs); } + if (time() - $iStartTime > 60) { + file_put_contents(CONST_BasePath.'/log/long_queries.log', date('Y-m-d H:i:s', $iStartTime).' '.$sSQL."\n", FILE_APPEND); + } + //var_dump($aViewBoxPlaceIDs); // Did we have an viewbox matches? $aPlaceIDs = array(); @@ -1312,10 +1321,10 @@ $bFirst = false; } if (!$bDeDupe || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']]) - && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['osm_class'].$aResult['name']]))) + && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['name']]))) { $aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true; - $aClassTypeNameDone[$aResult['osm_type'].$aResult['osm_class'].$aResult['name']] = true; + $aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['name']] = true; $aSearchResults[] = $aResult; }