mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-11 21:34:06 +00:00
add option to filter by countrycodes=gb,fr list
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
$sOutputFormat = 'html';
|
$sOutputFormat = 'html';
|
||||||
$aSearchResults = array();
|
$aSearchResults = array();
|
||||||
$aExcludePlaceIDs = array();
|
$aExcludePlaceIDs = array();
|
||||||
|
$sCountryCodesSQL = false;
|
||||||
$sSuggestion = $sSuggestionURL = false;
|
$sSuggestion = $sSuggestionURL = false;
|
||||||
$bDeDupe = isset($_GET['dedupe'])?(bool)$_GET['dedupe']:true;
|
$bDeDupe = isset($_GET['dedupe'])?(bool)$_GET['dedupe']:true;
|
||||||
$bReverseInPlan = false;
|
$bReverseInPlan = false;
|
||||||
@@ -41,8 +42,6 @@
|
|||||||
if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
|
if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
|
||||||
if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
|
if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
|
||||||
|
|
||||||
$bReverseInPlan = true;
|
|
||||||
|
|
||||||
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
|
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
|
||||||
|
|
||||||
if (isset($_GET['exclude_place_ids']) && $_GET['exclude_place_ids'])
|
if (isset($_GET['exclude_place_ids']) && $_GET['exclude_place_ids'])
|
||||||
@@ -75,6 +74,19 @@ $bReverseInPlan = true;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['countrycodes']))
|
||||||
|
{
|
||||||
|
$aCountryCodes = array();
|
||||||
|
foreach(explode(',',$_GET['countrycodes']) as $sCountryCode)
|
||||||
|
{
|
||||||
|
if (preg_match('/^[a-zA-Z][a-zA-Z]$/', $sCountryCode))
|
||||||
|
{
|
||||||
|
$aCountryCodes[] = "'".strtolower($sCountryCode)."'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sCountryCodesSQL = join(',', $aCountryCodes);
|
||||||
|
}
|
||||||
|
|
||||||
// Search query
|
// Search query
|
||||||
$sQuery = (isset($_GET['q'])?trim($_GET['q']):'');
|
$sQuery = (isset($_GET['q'])?trim($_GET['q']):'');
|
||||||
@@ -658,7 +670,9 @@ $bReverseInPlan = true;
|
|||||||
if ($oDB->getOne($sSQL))
|
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'];
|
||||||
|
if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)";
|
||||||
$sSQL .= " where st_contains($sViewboxSmallSQL, centroid)";
|
$sSQL .= " where st_contains($sViewboxSmallSQL, 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, centroid) asc";
|
||||||
$sSQL .= " limit $iLimit";
|
$sSQL .= " limit $iLimit";
|
||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
@@ -667,7 +681,9 @@ $bReverseInPlan = true;
|
|||||||
if (!sizeof($aPlaceIDs))
|
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'];
|
||||||
|
if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)";
|
||||||
$sSQL .= " where st_contains($sViewboxLargeSQL, centroid)";
|
$sSQL .= " where st_contains($sViewboxLargeSQL, 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, centroid) asc";
|
||||||
$sSQL .= " limit $iLimit";
|
$sSQL .= " limit $iLimit";
|
||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
@@ -678,6 +694,7 @@ $bReverseInPlan = true;
|
|||||||
{
|
{
|
||||||
$sSQL = "select place_id from placex where class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
|
$sSQL = "select place_id from placex where class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
|
||||||
$sSQL .= " and st_contains($sViewboxSmallSQL, centroid)";
|
$sSQL .= " and st_contains($sViewboxSmallSQL, 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, centroid) asc";
|
||||||
$sSQL .= " limit $iLimit";
|
$sSQL .= " limit $iLimit";
|
||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
@@ -707,6 +724,11 @@ $bReverseInPlan = true;
|
|||||||
{
|
{
|
||||||
$aTerms[] = "place_id not in (".join(',',$aExcludePlaceIDs).")";
|
$aTerms[] = "place_id not in (".join(',',$aExcludePlaceIDs).")";
|
||||||
}
|
}
|
||||||
|
if ($sCountryCodesSQL)
|
||||||
|
{
|
||||||
|
$aTerms[] = "country_code in ($sCountryCodesSQL)";
|
||||||
|
}
|
||||||
|
|
||||||
if ($bBoundingBoxSearch) $aTerms[] = "centroid && $sViewboxSmallSQL";
|
if ($bBoundingBoxSearch) $aTerms[] = "centroid && $sViewboxSmallSQL";
|
||||||
if ($sNearPointSQL) $aOrder[] = "ST_Distance($sNearPointSQL, centroid) asc";
|
if ($sNearPointSQL) $aOrder[] = "ST_Distance($sNearPointSQL, centroid) asc";
|
||||||
|
|
||||||
@@ -809,6 +831,7 @@ $bReverseInPlan = true;
|
|||||||
{
|
{
|
||||||
// If they were searching for a named class (i.e. 'Kings Head pub') then we might have an extra match
|
// 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 = "select place_id from placex where place_id in ($sPlaceIDs) and class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
|
||||||
|
if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";
|
||||||
$sSQL .= " order by rank_search asc limit $iLimit";
|
$sSQL .= " order by rank_search asc limit $iLimit";
|
||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
$aPlaceIDs = $oDB->getCol($sSQL);
|
$aPlaceIDs = $oDB->getCol($sSQL);
|
||||||
@@ -817,6 +840,7 @@ $bReverseInPlan = true;
|
|||||||
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'near') // & in
|
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'near') // & in
|
||||||
{
|
{
|
||||||
$sSQL = "select rank_search from placex where place_id in ($sPlaceIDs) order by rank_search asc limit 1";
|
$sSQL = "select rank_search from placex where place_id in ($sPlaceIDs) order by rank_search asc limit 1";
|
||||||
|
|
||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
$iMaxRank = ((int)$oDB->getOne($sSQL)) + 5;
|
$iMaxRank = ((int)$oDB->getOne($sSQL)) + 5;
|
||||||
|
|
||||||
@@ -835,12 +859,14 @@ $bReverseInPlan = true;
|
|||||||
// More efficient - can make the range bigger
|
// More efficient - can make the range bigger
|
||||||
$fRange = 0.05;
|
$fRange = 0.05;
|
||||||
$sSQL = "select l.place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
|
$sSQL = "select l.place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
|
||||||
|
if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)";
|
||||||
$sSQL .= ",placex as f where ";
|
$sSQL .= ",placex as f where ";
|
||||||
$sSQL .= "f.place_id in ($sPlaceIDs) and ST_DWithin(l.centroid, st_centroid(f.geometry), $fRange) ";
|
$sSQL .= "f.place_id in ($sPlaceIDs) and ST_DWithin(l.centroid, st_centroid(f.geometry), $fRange) ";
|
||||||
if (sizeof($aExcludePlaceIDs))
|
if (sizeof($aExcludePlaceIDs))
|
||||||
{
|
{
|
||||||
$sSQL .= " and l.place_id not in (".join(',',$aExcludePlaceIDs).")";
|
$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";
|
if ($sNearPointSQL) $sSQL .= " order by ST_Distance($sNearPointSQL, l.centroid) ASC";
|
||||||
else $sSQL .= " order by ST_Distance(l.centroid, f.geometry) asc";
|
else $sSQL .= " order by ST_Distance(l.centroid, f.geometry) asc";
|
||||||
$sSQL .= " limit $iLimit";
|
$sSQL .= " limit $iLimit";
|
||||||
@@ -857,6 +883,7 @@ $bReverseInPlan = true;
|
|||||||
{
|
{
|
||||||
$sSQL .= " and l.place_id not in (".join(',',$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";
|
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";
|
else $sSQL .= " order by ST_Distance(l.geometry, f.geometry) asc, l.rank_search ASC";
|
||||||
$sSQL .= " limit $iLimit";
|
$sSQL .= " limit $iLimit";
|
||||||
|
|||||||
Reference in New Issue
Block a user