]> git.openstreetmap.org Git - nominatim.git/commitdiff
implement namedetails and extratags parameter for search
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 10 Aug 2015 19:42:40 +0000 (21:42 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 10 Aug 2015 19:42:40 +0000 (21:42 +0200)
lib/Geocode.php
lib/template/address-xml.php
lib/template/search-json.php
lib/template/search-jsonv2.php
lib/template/search-xml.php
website/search.php

index c89cc48cff856531860a0eadcf084913566f4110..93498c334c0990197104ad92808942358bc9cb64 100644 (file)
@@ -6,6 +6,8 @@
                protected $aLangPrefOrder = array();
 
                protected $bIncludeAddressDetails = false;
+               protected $bIncludeExtraTags = false;
+               protected $bIncludeNameDetails = false;
 
                protected $bIncludePolygonAsPoints = false;
                protected $bIncludePolygonAsText = false;
                        return $this->bIncludeAddressDetails;
                }
 
+               function getIncludeExtraTags()
+               {
+                       return $this->bIncludeExtraTags;
+               }
+
+               function getIncludeNameDetails()
+               {
+                       return $this->bIncludeNameDetails;
+               }
+
                function setIncludePolygonAsPoints($b = true)
                {
                        $this->bIncludePolygonAsPoints = $b;
                function loadParamArray($aParams)
                {
                        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['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
 
                        $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,";
+                       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 .= $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 .= ",langaddress ";
                        $sSQL .= ",placename ";
                        $sSQL .= ",ref ";
+                       if ($this->bIncludeExtraTags) $sSQL .= ",extratags";
+                       if ($this->bIncludeNameDetails) $sSQL .= ",name";
                        $sSQL .= ",extratags->'place' ";
 
                        if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank)
                                $sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
                                $sSQL .= "null as placename,";
                                $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 .= $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 .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
                                $sSQL .= "null as placename,";
                                $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 .= $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, ";
                                        }
                                }
 
+                               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
                                $aResult['importance'] = max(0.001,$aResult['importance']);
                                $iCountWords = 0;
                                {
                                        $aResult['foundorder'] += 0.01;
                                }
+                               if (CONST_Debug) { var_dump($aResult); }
                                $aSearchResults[$iResNum] = $aResult;
                        }
                        uasort($aSearchResults, 'byImportance');
index ba085eea9fd27b757270659d8a6e374b0dbf7c5a..39d9a14792171a0c0d0cd0efc60ff8fa73c7257b 100644 (file)
@@ -47,9 +47,7 @@
                        echo "<extratags>";
                        foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
                        {
-                               echo '<tag key="'.htmlspecialchars($sKey).'">';
-                               echo htmlspecialchars($sValue);
-                               echo "</tag>";
+                               echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
                        }
                        echo "</extratags>";
                }
@@ -59,7 +57,7 @@
                        echo "<namedetails>";
                        foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
                        {
-                               echo '<name key="'.htmlspecialchars($sKey).'">';
+                               echo '<name desc="'.htmlspecialchars($sKey).'">';
                                echo htmlspecialchars($sValue);
                                echo "</name>";
                        }
index 57586fb9eee3c3adeb24003e225d64fb11480aaf..3dcaabdbd6393a94bc27b375c1c401db11626a69 100644 (file)
@@ -74,6 +74,9 @@
                        $aPlace['geokml'] = $aPointDetails['askml'];
                }
 
+               if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
+               if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
+
                $aFilteredPlaces[] = $aPlace;
        }
 
index 126f78662df64970a3acc6c120599637fdaf975d..8006e3c2e02c2b9be965b1c65f0a68947cde1d85 100644 (file)
@@ -73,6 +73,9 @@
                         $aPlace['geokml'] = $aPointDetails['askml'];
                 }
 
+               if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
+               if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
+
                $aFilteredPlaces[] = $aPlace;
        }
 
index c1fd58f02ed4f612424eeebdd3d1829394207f15..b61ff22f55fe2eed589466c682a8f650ac14b52b 100644 (file)
                        echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
                }
 
-               if (isset($aResult['address']) || isset($aResult['askml']))
-               {
-                       echo ">";
-               }
+               $bHasDelim = false;
 
                if (isset($aResult['askml']))
                {
+                       if (!$bHasDelim)
+                       {
+                               $bHasDelim = true;
+                               echo ">";
+                       }
                        echo "\n<geokml>";
                        echo $aResult['askml'];
                        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 (!$bHasDelim)
+                       {
+                               $bHasDelim = true;
+                               echo ">";
+                       }
                        echo "\n";
                        foreach($aResult['address'] as $sKey => $sValue)
                        {
                        }
                }
 
-               if (isset($aResult['address']) || isset($aResult['askml']))
+               if ($bHasDelim)
                {
                        echo "</place>";
                }
index bf27ef9a8157e734536b60196f35f009cf3d19ba..b18c391ea2f62aaa470371358a1547f5e6b0cb43 100755 (executable)
        if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
        if ($bShowPolygons) $sMoreURL .= '&polygon=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 (isset($_GET['nearlat']) && isset($_GET['nearlon'])) $sMoreURL .= '&nearlat='.(float)$_GET['nearlat'].'&nearlon='.(float)$_GET['nearlon'];
        $sMoreURL .= '&q='.urlencode($sQuery);