X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3d8d52632b20b96e2236330c49c88a33c999e72f..5502c223756ed755edae9670497f1456e528d3f0:/website/search.php
diff --git a/website/search.php b/website/search.php
index e00d8791..77a3d135 100755
--- a/website/search.php
+++ b/website/search.php
@@ -71,6 +71,7 @@
if (isset($aLangPrefOrder['name:de'])) $bReverseInPlan = true;
if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
+ if (isset($aLangPrefOrder['name:pl'])) $bReverseInPlan = true;
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
@@ -163,7 +164,10 @@
}
if (sizeof($aStructuredQuery) > 0) {
$sQuery = join(', ', $aStructuredQuery);
- $sAllowedTypesSQLList = '(\'place\',\'boundary\')';
+ if ($iMaxAddressRank < 30)
+ {
+ $sAllowedTypesSQLList = '(\'place\',\'boundary\')';
+ }
}
if ($sQuery)
@@ -805,6 +809,10 @@
{
$iQueryLoop++;
+ if (CONST_Debug) { echo "
Search Loop, group $iGroupLoop, loop $iQueryLoop"; }
+ if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
+
+
// Must have a location term
if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['fLon'])
{
@@ -812,9 +820,10 @@
{
if (4 >= $iMinAddressRank && 4 <= $iMaxAddressRank)
{
- $sSQL = "select place_id from placex where country_code='".$aSearch['sCountryCode']."' and rank_search = 4";
- if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
+ $sSQL = "select place_id from placex where calculated_country_code='".$aSearch['sCountryCode']."' and rank_search = 4";
+ if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
$sSQL .= " order by st_area(geometry) desc limit 1";
+ if (CONST_Debug) var_dump($sSQL);
$aPlaceIDs = $oDB->getCol($sSQL);
}
}
@@ -822,15 +831,13 @@
{
if (!$bBoundingBoxSearch && !$aSearch['fLon']) continue;
if (!$aSearch['sClass']) continue;
- if (CONST_Debug) var_dump('
',$aSearch);
- if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
$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']." ct";
if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)";
$sSQL .= " where st_contains($sViewboxSmallSQL, ct.centroid)";
- if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
if (sizeof($aExcludePlaceIDs))
{
$sSQL .= " and place_id not in (".join(',',$aExcludePlaceIDs).")";
@@ -848,7 +855,7 @@
$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, ct.centroid)";
- if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, ct.centroid) asc";
$sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL);
@@ -859,7 +866,7 @@
{
$sSQL = "select place_id from placex where class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
$sSQL .= " and st_contains($sViewboxSmallSQL, geometry) and linked_place_id is null";
- if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, centroid) asc";
$sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL);
@@ -869,8 +876,6 @@
}
else
{
- if (CONST_Debug) var_dump('
',$aSearch);
- if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
$aPlaceIDs = array();
// First we need a position, either aName or fLat or both
@@ -932,12 +937,17 @@
else
$sSQL .= " limit ".$iLimit;
- if (CONST_Debug) { var_dump($sSQL); }
+ 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();
@@ -1014,7 +1024,7 @@
// If they were searching for a named class (i.e. 'Kings Head pub') then we might have an extra match
$sSQL = "select place_id from placex where place_id in ($sPlaceIDs) and class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
$sSQL .= " and linked_place_id is null";
- if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
$sSQL .= " order by rank_search asc limit $iLimit";
if (CONST_Debug) var_dump($sSQL);
$aClassPlaceIDs = $oDB->getCol($sSQL);
@@ -1083,7 +1093,7 @@
{
$sSQL .= " and l.place_id not in (".join(',',$aExcludePlaceIDs).")";
}
- if ($sCountryCodesSQL) $sSQL .= " and lp.country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and lp.calculated_country_code in ($sCountryCodesSQL)";
if ($sOrderBySQL) $sSQL .= "order by ".$sOrderBySQL." asc";
if ($iOffset) $sSQL .= " offset $iOffset";
$sSQL .= " limit $iLimit";
@@ -1105,7 +1115,7 @@
{
$sSQL .= " and l.place_id not in (".join(',',$aExcludePlaceIDs).")";
}
- if ($sCountryCodesSQL) $sSQL .= " and l.country_code in ($sCountryCodesSQL)";
+ if ($sCountryCodesSQL) $sSQL .= " and l.calculated_country_code in ($sCountryCodesSQL)";
if ($sOrderBy) $sSQL .= "order by ".$OrderBysSQL." asc";
if ($iOffset) $sSQL .= " offset $iOffset";
$sSQL .= " limit $iLimit";
@@ -1126,7 +1136,7 @@
failInternalError("Could not get place IDs from tokens." ,$sSQL, $aPlaceIDs);
}
- if (CONST_Debug) var_Dump($aPlaceIDs);
+ if (CONST_Debug) { echo "
Place IDs: "; var_Dump($aPlaceIDs); }
foreach($aPlaceIDs as $iPlaceID)
{
@@ -1140,7 +1150,7 @@
if ($iGroupLoop > 4) break;
if ($iQueryLoop > 30) break;
}
-//exit;
+
// Did we find anything?
if (isset($aResultPlaceIDs) && sizeof($aResultPlaceIDs))
{
@@ -1153,7 +1163,7 @@
$sOrderSQL .= 'when min(place_id) = '.$iPlaceID.' then '.$iOrder.' ';
}
$sOrderSQL .= ' ELSE 10000000 END';
- $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id,country_code,";
+ $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id,calculated_country_code as country_code,";
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
@@ -1164,7 +1174,7 @@
$sSQL .= "and placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
if ($sAllowedTypesSQLList) $sSQL .= "and placex.class in $sAllowedTypesSQLList ";
$sSQL .= "and linked_place_id is null ";
- $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code,importance";
+ $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,calculated_country_code,importance";
if (!$bDeDupe) $sSQL .= ",place_id";
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= ",get_name_by_language(name, $sLanguagePrefArraySQL) ";
@@ -1196,7 +1206,7 @@
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= "order by importance desc";
// $sSQL .= "order by rank_search,rank_address,porder asc";
- if (CONST_Debug) var_dump('
',$sSQL);
+ if (CONST_Debug) { echo "
"; var_dump($sSQL); }
$aSearchResults = $oDB->getAll($sSQL);
//var_dump($sSQL,$aSearchResults);exit;
@@ -1223,7 +1233,7 @@
$sOrderSQL .= 'when min(place_id) = '.$iPlaceID.' then '.$iOrder.' ';
}
$sOrderSQL .= ' ELSE 10000000 END';
- $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id,country_code,";
+ $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id,calculated_country_code as country_code,";
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
@@ -1232,7 +1242,7 @@
$sSQL .= "coalesce(importance,0.75-(rank_search::float/40)) as importance ";
$sSQL .= "from placex where place_id in ($sPlaceIDs) ";
$sSQL .= "and placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
- $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code,importance";
+ $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,calculated_country_code,importance";
if (!$bDeDupe) $sSQL .= ",place_id";
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= ",get_name_by_language(name, $sLanguagePrefArraySQL) ";
@@ -1264,7 +1274,7 @@
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= "order by importance desc";
// $sSQL .= "order by rank_search,rank_address,porder asc";
- if (CONST_Debug) var_dump('
',$sSQL);
+ if (CONST_Debug) { echo "
", var_dump($sSQL); }
$aSearchResults = $oDB->getAll($sSQL);
//var_dump($sSQL,$aSearchResults);exit;