mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
implement namedetails and extratags parameter for search
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
protected $aLangPrefOrder = array();
|
protected $aLangPrefOrder = array();
|
||||||
|
|
||||||
protected $bIncludeAddressDetails = false;
|
protected $bIncludeAddressDetails = false;
|
||||||
|
protected $bIncludeExtraTags = false;
|
||||||
|
protected $bIncludeNameDetails = false;
|
||||||
|
|
||||||
protected $bIncludePolygonAsPoints = false;
|
protected $bIncludePolygonAsPoints = false;
|
||||||
protected $bIncludePolygonAsText = false;
|
protected $bIncludePolygonAsText = false;
|
||||||
@@ -68,6 +70,16 @@
|
|||||||
return $this->bIncludeAddressDetails;
|
return $this->bIncludeAddressDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIncludeExtraTags()
|
||||||
|
{
|
||||||
|
return $this->bIncludeExtraTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIncludeNameDetails()
|
||||||
|
{
|
||||||
|
return $this->bIncludeNameDetails;
|
||||||
|
}
|
||||||
|
|
||||||
function setIncludePolygonAsPoints($b = true)
|
function setIncludePolygonAsPoints($b = true)
|
||||||
{
|
{
|
||||||
$this->bIncludePolygonAsPoints = $b;
|
$this->bIncludePolygonAsPoints = $b;
|
||||||
@@ -214,6 +226,8 @@
|
|||||||
function loadParamArray($aParams)
|
function loadParamArray($aParams)
|
||||||
{
|
{
|
||||||
if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
|
if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
|
||||||
|
if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
|
||||||
|
if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
|
||||||
if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
|
if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
|
||||||
if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
|
if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
|
||||||
|
|
||||||
@@ -389,6 +403,8 @@
|
|||||||
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
|
$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, $sLanguagePrefArraySQL) as placename,";
|
||||||
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
|
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
|
||||||
|
if ($this->bIncludeExtraTags) $sSQL .= "hstore_to_json(extratags)::text as extra,";
|
||||||
|
if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text as names,";
|
||||||
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
||||||
$sSQL .= $sImportanceSQL."coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
|
$sSQL .= $sImportanceSQL."coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
|
||||||
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
||||||
@@ -405,6 +421,8 @@
|
|||||||
$sSQL .= ",langaddress ";
|
$sSQL .= ",langaddress ";
|
||||||
$sSQL .= ",placename ";
|
$sSQL .= ",placename ";
|
||||||
$sSQL .= ",ref ";
|
$sSQL .= ",ref ";
|
||||||
|
if ($this->bIncludeExtraTags) $sSQL .= ",extratags";
|
||||||
|
if ($this->bIncludeNameDetails) $sSQL .= ",name";
|
||||||
$sSQL .= ",extratags->'place' ";
|
$sSQL .= ",extratags->'place' ";
|
||||||
|
|
||||||
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank)
|
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank)
|
||||||
@@ -414,6 +432,8 @@
|
|||||||
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
|
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
|
||||||
$sSQL .= "null as placename,";
|
$sSQL .= "null as placename,";
|
||||||
$sSQL .= "null as ref,";
|
$sSQL .= "null as ref,";
|
||||||
|
if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
|
||||||
|
if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
|
||||||
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
||||||
$sSQL .= $sImportanceSQL."-1.15 as importance, ";
|
$sSQL .= $sImportanceSQL."-1.15 as importance, ";
|
||||||
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_tiger.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_tiger.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
||||||
@@ -427,6 +447,8 @@
|
|||||||
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
|
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
|
||||||
$sSQL .= "null as placename,";
|
$sSQL .= "null as placename,";
|
||||||
$sSQL .= "null as ref,";
|
$sSQL .= "null as ref,";
|
||||||
|
if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
|
||||||
|
if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
|
||||||
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
|
||||||
$sSQL .= $sImportanceSQL."-1.10 as importance, ";
|
$sSQL .= $sImportanceSQL."-1.10 as importance, ";
|
||||||
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_aux.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_aux.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
|
||||||
@@ -1756,6 +1778,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->bIncludeExtraTags)
|
||||||
|
{
|
||||||
|
if ($aResult['extra'])
|
||||||
|
{
|
||||||
|
$aResult['sExtraTags'] = json_decode($aResult['extra']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aResult['sExtraTags'] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->bIncludeNameDetails)
|
||||||
|
{
|
||||||
|
if ($aResult['names'])
|
||||||
|
{
|
||||||
|
$aResult['sNameDetails'] = json_decode($aResult['names']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aResult['sNameDetails'] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Adjust importance for the number of exact string matches in the result
|
// Adjust importance for the number of exact string matches in the result
|
||||||
$aResult['importance'] = max(0.001,$aResult['importance']);
|
$aResult['importance'] = max(0.001,$aResult['importance']);
|
||||||
$iCountWords = 0;
|
$iCountWords = 0;
|
||||||
@@ -1790,6 +1836,7 @@
|
|||||||
{
|
{
|
||||||
$aResult['foundorder'] += 0.01;
|
$aResult['foundorder'] += 0.01;
|
||||||
}
|
}
|
||||||
|
if (CONST_Debug) { var_dump($aResult); }
|
||||||
$aSearchResults[$iResNum] = $aResult;
|
$aSearchResults[$iResNum] = $aResult;
|
||||||
}
|
}
|
||||||
uasort($aSearchResults, 'byImportance');
|
uasort($aSearchResults, 'byImportance');
|
||||||
|
|||||||
@@ -47,9 +47,7 @@
|
|||||||
echo "<extratags>";
|
echo "<extratags>";
|
||||||
foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
|
foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
|
||||||
{
|
{
|
||||||
echo '<tag key="'.htmlspecialchars($sKey).'">';
|
echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
|
||||||
echo htmlspecialchars($sValue);
|
|
||||||
echo "</tag>";
|
|
||||||
}
|
}
|
||||||
echo "</extratags>";
|
echo "</extratags>";
|
||||||
}
|
}
|
||||||
@@ -59,7 +57,7 @@
|
|||||||
echo "<namedetails>";
|
echo "<namedetails>";
|
||||||
foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
|
foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
|
||||||
{
|
{
|
||||||
echo '<name key="'.htmlspecialchars($sKey).'">';
|
echo '<name desc="'.htmlspecialchars($sKey).'">';
|
||||||
echo htmlspecialchars($sValue);
|
echo htmlspecialchars($sValue);
|
||||||
echo "</name>";
|
echo "</name>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,9 @@
|
|||||||
$aPlace['geokml'] = $aPointDetails['askml'];
|
$aPlace['geokml'] = $aPointDetails['askml'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
|
||||||
|
if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
|
||||||
|
|
||||||
$aFilteredPlaces[] = $aPlace;
|
$aFilteredPlaces[] = $aPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,9 @@
|
|||||||
$aPlace['geokml'] = $aPointDetails['askml'];
|
$aPlace['geokml'] = $aPointDetails['askml'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
|
||||||
|
if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
|
||||||
|
|
||||||
$aFilteredPlaces[] = $aPlace;
|
$aFilteredPlaces[] = $aPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,20 +88,59 @@
|
|||||||
echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
|
echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($aResult['address']) || isset($aResult['askml']))
|
$bHasDelim = false;
|
||||||
{
|
|
||||||
echo ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($aResult['askml']))
|
if (isset($aResult['askml']))
|
||||||
{
|
{
|
||||||
|
if (!$bHasDelim)
|
||||||
|
{
|
||||||
|
$bHasDelim = true;
|
||||||
|
echo ">";
|
||||||
|
}
|
||||||
echo "\n<geokml>";
|
echo "\n<geokml>";
|
||||||
echo $aResult['askml'];
|
echo $aResult['askml'];
|
||||||
echo "</geokml>";
|
echo "</geokml>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($aResult['sExtraTags']))
|
||||||
|
{
|
||||||
|
if (!$bHasDelim)
|
||||||
|
{
|
||||||
|
$bHasDelim = true;
|
||||||
|
echo ">";
|
||||||
|
}
|
||||||
|
echo "\n<extratags>";
|
||||||
|
foreach ($aResult['sExtraTags'] as $sKey => $sValue)
|
||||||
|
{
|
||||||
|
echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
|
||||||
|
}
|
||||||
|
echo "</extratags>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($aResult['sNameDetails']))
|
||||||
|
{
|
||||||
|
if (!$bHasDelim)
|
||||||
|
{
|
||||||
|
$bHasDelim = true;
|
||||||
|
echo ">";
|
||||||
|
}
|
||||||
|
echo "\n<namedetails>";
|
||||||
|
foreach ($aResult['sNameDetails'] as $sKey => $sValue)
|
||||||
|
{
|
||||||
|
echo '<name desc="'.htmlspecialchars($sKey).'">';
|
||||||
|
echo htmlspecialchars($sValue);
|
||||||
|
echo "</name>";
|
||||||
|
}
|
||||||
|
echo "</namedetails>";
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($aResult['address']))
|
if (isset($aResult['address']))
|
||||||
{
|
{
|
||||||
|
if (!$bHasDelim)
|
||||||
|
{
|
||||||
|
$bHasDelim = true;
|
||||||
|
echo ">";
|
||||||
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
foreach($aResult['address'] as $sKey => $sValue)
|
foreach($aResult['address'] as $sKey => $sValue)
|
||||||
{
|
{
|
||||||
@@ -112,7 +151,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($aResult['address']) || isset($aResult['askml']))
|
if ($bHasDelim)
|
||||||
{
|
{
|
||||||
echo "</place>";
|
echo "</place>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,8 @@
|
|||||||
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
|
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
|
||||||
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
|
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
|
||||||
if ($oGeocode->getIncludeAddressDetails()) $sMoreURL .= '&addressdetails=1';
|
if ($oGeocode->getIncludeAddressDetails()) $sMoreURL .= '&addressdetails=1';
|
||||||
|
if ($oGeocode->getIncludeExtraTags()) $sMoreURL .= '&extratags=1';
|
||||||
|
if ($oGeocode->getIncludeNameDetails()) $sMoreURL .= '&namedetails=1';
|
||||||
if ($sViewBox) $sMoreURL .= '&viewbox='.urlencode($sViewBox);
|
if ($sViewBox) $sMoreURL .= '&viewbox='.urlencode($sViewBox);
|
||||||
if (isset($_GET['nearlat']) && isset($_GET['nearlon'])) $sMoreURL .= '&nearlat='.(float)$_GET['nearlat'].'&nearlon='.(float)$_GET['nearlon'];
|
if (isset($_GET['nearlat']) && isset($_GET['nearlon'])) $sMoreURL .= '&nearlat='.(float)$_GET['nearlat'].'&nearlon='.(float)$_GET['nearlon'];
|
||||||
$sMoreURL .= '&q='.urlencode($sQuery);
|
$sMoreURL .= '&q='.urlencode($sQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user