]> git.openstreetmap.org Git - nominatim.git/commitdiff
move moreURL computation into Geocode and include all params
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 22 Mar 2017 23:16:58 +0000 (00:16 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 22 Mar 2017 23:16:58 +0000 (00:16 +0100)
Fixes #678.

lib/Geocode.php
lib/template/search-html.php
lib/template/search-json.php
lib/template/search-jsonv2.php
lib/template/search-xml.php
test/bdd/api/search/simple.feature
website/search.php

index 589220358f6514df2242f6a9296330973fca846f..971eb85dab757a70cc4b59af126ede9df75d51bd 100644 (file)
@@ -67,19 +67,45 @@ class Geocode
         $this->aLangPrefOrder = $aLangPref;
     }
 
-    public function getIncludeAddressDetails()
+    public function getMoreUrlParams()
     {
-        return $this->bIncludeAddressDetails;
-    }
+        if ($this->aStructuredQuery) {
+            $aParams = $this->aStructuredQuery;
+        } else {
+            $aParams = array('q' => $this->sQuery);
+        }
 
-    public function getIncludeExtraTags()
-    {
-        return $this->bIncludeExtraTags;
-    }
+        if ($this->aExcludePlaceIDs) {
+            $aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs);
+        }
 
-    public function getIncludeNameDetails()
-    {
-        return $this->bIncludeNameDetails;
+        if ($this->bIncludeAddressDetails) $aParams['addressdetails'] = '1';
+        if ($this->bIncludeExtraTags) $aParams['extratags'] = '1';
+        if ($this->bIncludeNameDetails) $aParams['namedetails'] = '1';
+
+        if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
+        if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
+        if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
+        if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
+        if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
+
+        if ($this->fPolygonSimplificationThreshold > 0.0) {
+            $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
+        }
+
+        if ($this->bBoundedSearch) $aParams['bounded'] = '1';
+        if (!$this->bDeDupe) $aParams['dedupe'] = '0';
+
+        if ($this->aCountryCodes) {
+            $aParams['countrycodes'] = implode(',', $this->aCountryCodes);
+        }
+
+        if ($this->aViewBox) {
+            $aParams['viewbox'] = $this->aViewBox[0].','.$this->aViewBox[3]
+                                  .','.$this->aViewBox[2].','.$this->aViewBox[1];
+        }
+
+        return $aParams;
     }
 
     public function setIncludePolygonAsPoints($b = true)
@@ -121,23 +147,6 @@ class Geocode
         $this->iLimit = $iLimit + min($iLimit, 10);
     }
 
-    public function getExcludedPlaceIDs()
-    {
-        return $this->aExcludePlaceIDs;
-    }
-
-
-    public function getCountryCodes()
-    {
-        return $this->aCountryCodes;
-    }
-
-    public function getViewBoxString()
-    {
-        if (!$this->aViewBox) return null;
-        return $this->aViewBox[0].','.$this->aViewBox[3].','.$this->aViewBox[2].','.$this->aViewBox[1];
-    }
-
     public function setFeatureType($sFeatureType)
     {
         switch ($sFeatureType) {
@@ -341,7 +350,7 @@ class Geocode
         return true;
     }
 
-    public function setStructuredQuery($sAmentiy = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
+    public function setStructuredQuery($sAmenity = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
     {
         $this->sQuery = false;
 
@@ -353,7 +362,7 @@ class Geocode
         $this->aStructuredQuery = array();
         $this->sAllowedTypesSQLList = '';
 
-        $this->loadStructuredAddressElement($sAmentiy, 'amenity', 26, 30, false);
+        $this->loadStructuredAddressElement($sAmenity, 'amenity', 26, 30, false);
         $this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
         $this->loadStructuredAddressElement($sCity, 'city', 14, 24, false);
         $this->loadStructuredAddressElement($sCounty, 'county', 9, 13, false);
index 115f1813e1359ae7791dd65dc4cd37f1be2c25f2..37a6ce4a8b8e85916f9a0a3fa375e3a9fb89c013 100644 (file)
         <div class="form-group search-button-group">
             <button type="submit" class="btn btn-primary btn-sm">Search</button>
             <?php if (CONST_Search_AreaPolygons) { ?>
-                <!-- <input type="checkbox" value="1" name="polygon_geojson" <?php if ($bAsGeoJSON) echo "checked='checked'"; ?>/> Highlight -->
                 <input type="hidden" value="1" name="polygon_geojson" />
             <?php } ?>
-            <input type="hidden" name="viewbox" value="<?php echo $sViewBox; ?>" />
+            <input type="hidden" name="viewbox" value="<?php if (isset($aMoreParams['viewbox'])) echo ($aMoreParams['viewbox']); ?>" />
             <div class="checkbox-inline">
-                <input type="checkbox" id="use_viewbox" <?php if ($sViewBox) echo "checked='checked'"; ?>>
+                <input type="checkbox" id="use_viewbox" <?php if (isset($aMoreParams['viewbox'])) echo "checked='checked'"; ?>>
                 <label for="use_viewbox">apply viewbox</label>
             </div>
         </div>
index ee2b4bd280b99e0d6df1dd9e45ee27226dde9202..50009bc375023e70982331bee7808844456ef900 100644 (file)
@@ -20,7 +20,7 @@ foreach($aSearchResults as $iResNum => $aPointDetails)
     {
         $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
 
-        if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
+        if (isset($aPointDetails['aPolyPoints']))
         {
             $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
         }
index 35538797184808477ae7b96d9f33e7a69bac66bd..d550a7e6706d19d6ea09f97031703b503657f089 100644 (file)
@@ -19,7 +19,7 @@ foreach($aSearchResults as $iResNum => $aPointDetails)
     {
         $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
 
-        if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
+        if (isset($aPointDetails['aPolyPoints']))
         {
             $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
         }
index 80091b0aeedecc123c4ab0e3d4f7c2a2bacd7aed..80414fce6829be2f18534e06431aabbb2b9f8db3 100644 (file)
@@ -10,16 +10,13 @@ echo (isset($sXmlRootTag)?$sXmlRootTag:'searchresults');
 echo " timestamp='".date(DATE_RFC822)."'";
 echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
 echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'";
-if ($sViewBox) echo " viewbox='".htmlspecialchars($sViewBox, ENT_QUOTES)."'";
-echo " polygon='".($bShowPolygons?'true':'false')."'";
-if (sizeof($aExcludePlaceIDs))
+if (isset($aMoreParams['viewbox'])) echo " viewbox='".htmlspecialchars($aMoreParams['viewbox'], ENT_QUOTES)."'";
+echo " polygon='".(isset($aMoreParams['polygon'])?'true':'false')."'";
+if (isset($aMoreParams['exclude_place_ids']))
 {
-    echo " exclude_place_ids='".htmlspecialchars(join(',',$aExcludePlaceIDs))."'";
-}
-if ($sMoreURL)
-{
-    echo " more_url='".htmlspecialchars($sMoreURL)."'";
+    echo " exclude_place_ids='".htmlspecialchars($aMoreParams['exclude_place_ids'])."'";
 }
+echo " more_url='".htmlspecialchars($sMoreURL)."'";
 echo ">\n";
 
 foreach($aSearchResults as $iResNum => $aResult)
@@ -39,7 +36,7 @@ foreach($aSearchResults as $iResNum => $aResult)
         echo join(',',$aResult['aBoundingBox']);
         echo '"';
 
-        if ($bShowPolygons && isset($aResult['aPolyPoints']))
+        if (isset($aResult['aPolyPoints']))
         {
             echo ' polygonpoints=\'';
             echo json_encode($aResult['aPolyPoints']);
index b986d8a72c64280727cc589d26a6bf84db2d4315..aa8c8ce8c46afa50cc3c0e16753e560319132aae 100644 (file)
@@ -89,7 +89,7 @@ Feature: Simple Tests
           | attr        | value |
           | querystring | xnznxvcx |
           | polygon     | false |
-          | more_url    | .*format=xml.*q=xnznxvcx.* |
+          | more_url    | .*q=xnznxvcx.*format=xml |
 
     Scenario: Empty XML search with special XML characters
         When sending xml search query "xfdghn&zxn"xvbyx<vxx>cssdex"
@@ -97,7 +97,7 @@ Feature: Simple Tests
           | attr        | value |
           | querystring | xfdghn&zxn"xvbyx<vxx>cssdex |
           | polygon     | false |
-          | more_url    | .*format=xml.*q=xfdghn%26zxn%22xvbyx%3Cvxx%3Ecssdex.* |
+          | more_url    | .*q=xfdghn%26zxn%22xvbyx%3Cvxx%3Ecssdex.*format=xml |
 
     Scenario: Empty XML search with viewbox
         When sending xml search query "xnznxvcx"
@@ -225,4 +225,4 @@ Feature: Simple Tests
           | pl,1,,invalid,undefined,%3Cb%3E,bo,, |
        Then result header contains
           | attr     | value |
-          | more_url | .*&countrycodes=pl,bo&.* |
+          | more_url | .*&countrycodes=pl%2Cbo&.* |
index a4dbd64ad6bba3807cfa6464745dce48565273de..4952465e68ce858789fde582f45c42f5b1341431 100755 (executable)
@@ -99,19 +99,13 @@ if ($sOutputFormat=='html') {
 logEnd($oDB, $hLog, sizeof($aSearchResults));
 
 $sQuery = $oGeocode->getQueryString();
-$sViewBox = $oGeocode->getViewBoxString();
-$bShowPolygons = (isset($_GET['polygon']) && $_GET['polygon']);
-$aExcludePlaceIDs = $oGeocode->getExcludedPlaceIDs();
-
-$sMoreURL = CONST_Website_BaseURL.'search.php?format='.$sOutputFormat.'&exclude_place_ids='.join(',', $aExcludePlaceIDs);
-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 ($oGeocode->getCountryCodes()) $sMoreURL .= '&countrycodes='.join(',', $oGeocode->getCountryCodes());
-if ($sViewBox) $sMoreURL .= '&viewbox='.urlencode($sViewBox);
-$sMoreURL .= '&q='.urlencode($sQuery);
+
+$aMoreParams = $oGeocode->getMoreUrlParams();
+if ($sOutputFormat != 'html') $aMoreParams['format'] = $sOutputFormat;
+if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
+    $aMoreParams['accept-language'] = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
+}
+$sMoreURL = CONST_Website_BaseURL.'search.php?'.http_build_query($aMoreParams);
 
 if (CONST_Debug) exit;