]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 12 Mar 2014 17:30:27 +0000 (18:30 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 12 Mar 2014 17:30:27 +0000 (18:30 +0100)
.gitignore
lib/Geocode.php
lib/init-cmd.php
lib/lib.php
utils/query.php [new file with mode: 0755]
website/search.php

index 1c7d233eee573b53d84bfef74241a9452d3b5ba7..0c54ce7670719bc7c7816c652d242b30a5654d7b 100644 (file)
@@ -4,6 +4,7 @@ nominatim/*.d
 nominatim/*.o
 nominatim/nominatim
 module/nominatim.so
+module/nominatim.o
 settings/configuration.txt
 settings/download.lock
 settings/state.txt
@@ -19,3 +20,10 @@ stamp-h1
 missing
 INSTALL
 aclocal.m4
+depcomp
+install-sh
+compile
+
+data/wiki_import.sql
+data/wiki_specialphrases.sql
+data/osmosischange.osc
index b65cc2779924551f3eaf6510a2cd51005749a968..c345bf36a6e22964a9989c115fa1ebf4d4cc1c59 100644 (file)
                        return $this->sQuery;
                }
 
+
+               function loadParamArray($aParams)
+               {
+                       if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
+                       if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
+                       if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
+
+                       if (isset($aParams['limit'])) $this->setLimit((int)$aParams['limit']);
+                       if (isset($aParams['offset'])) $this->iOffset = (int)$aParams['offset'];
+
+                       if (isset($aParams['fallback'])) $this->bFallback = (bool)$aParams['fallback'];
+
+                       // List of excluded Place IDs - used for more acurate pageing
+                       if (isset($aParams['exclude_place_ids']) && $aParams['exclude_place_ids'])
+                       {
+                               foreach(explode(',',$aParams['exclude_place_ids']) as $iExcludedPlaceID)
+                               {
+                                       $iExcludedPlaceID = (int)$iExcludedPlaceID;
+                                       if ($iExcludedPlaceID) $aExcludePlaceIDs[$iExcludedPlaceID] = $iExcludedPlaceID;
+                               }
+                               $this->aExcludePlaceIDs = $aExcludePlaceIDs;
+                       }
+
+                       // Only certain ranks of feature
+                       if (isset($aParams['featureType'])) $this->setFeatureType($aParams['featureType']);
+                       if (isset($aParams['featuretype'])) $this->setFeatureType($aParams['featuretype']);
+
+                       // Country code list
+                       if (isset($aParams['countrycodes']))
+                       {
+                               $aCountryCodes = array();
+                               foreach(explode(',',$aParams['countrycodes']) as $sCountryCode)
+                               {
+                                       if (preg_match('/^[a-zA-Z][a-zA-Z]$/', $sCountryCode))
+                                       {
+                                               $aCountryCodes[] = strtolower($sCountryCode);
+                                       }
+                               }
+                               $this->aCountryCodes = $aCountryCodes;
+                       }
+
+                       if (isset($aParams['viewboxlbrt']) && $aParams['viewboxlbrt'])
+                       {
+                               $aCoOrdinatesLBRT = explode(',',$aParams['viewboxlbrt']);
+                               $this->setViewBox($aCoOrdinatesLBRT[0], $aCoOrdinatesLBRT[1], $aCoOrdinatesLBRT[2], $aCoOrdinatesLBRT[3]);
+                       }
+                       else if (isset($aParams['viewbox']) && $aParams['viewbox'])
+                       {
+                               $aCoOrdinatesLTRB = explode(',',$aParams['viewbox']);
+                               $this->setViewBox($aCoOrdinatesLTRB[0], $aCoOrdinatesLTRB[3], $aCoOrdinatesLTRB[2], $aCoOrdinatesLTRB[1]);
+                       }
+
+                       if (isset($aParams['route']) && $aParams['route'] && isset($aParams['routewidth']) && $aParams['routewidth'])
+                       {
+                               $aPoints = explode(',',$aParams['route']);
+                               if (sizeof($aPoints) % 2 != 0)
+                               {
+                                       userError("Uneven number of points");
+                                       exit;
+                               }
+                               $fPrevCoord = false;
+                               $aRoute = array();
+                               foreach($aPoints as $i => $fPoint)
+                               {
+                                       if ($i%2)
+                                       {
+                                               $aRoute[] = array((float)$fPoint, $fPrevCoord);
+                                       }
+                                       else
+                                       {
+                                               $fPrevCoord = (float)$fPoint;
+                                       }
+                               }
+                               $this->aRoutePoints = $aRoute;
+                       }
+               }
+
+               function setQueryFromParams($aParams)
+               {
+                       // Search query
+                       $sQuery = (isset($aParams['q'])?trim($aParams['q']):'');
+                       if (!$sQuery)
+                       {
+                               $this->setStructuredQuery(@$aParams['amenity'], @$aParams['street'], @$aParams['city'], @$aParams['county'], @$aParams['state'], @$aParams['country'], @$aParams['postalcode']);
+                               $this->setReverseInPlan(false);
+                       }
+                       else
+                       {
+                               $this->setQuery($sQuery);
+                       }
+               }
+
                function loadStructuredAddressElement($sValue, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank, $aItemListValues)
                {
                        $sValue = trim($sValue);
                        // Conflicts between US state abreviations and various words for 'the' in different languages
                        if (isset($this->aLangPrefOrder['name:en']))
                        {
-                               $sQuery = preg_replace('/,\s*il\s*(,|$)/',', illinois\1', $sQuery);
-                               $sQuery = preg_replace('/,\s*al\s*(,|$)/',', alabama\1', $sQuery);
-                               $sQuery = preg_replace('/,\s*la\s*(,|$)/',', louisiana\1', $sQuery);
+                               $sQuery = preg_replace('/(^|,)\s*il\s*(,|$)/','\1illinois\2', $sQuery);
+                               $sQuery = preg_replace('/(^|,)\s*al\s*(,|$)/','\1alabama\2', $sQuery);
+                               $sQuery = preg_replace('/(^|,)\s*la\s*(,|$)/','\1louisiana\2', $sQuery);
                        }
 
                        // View Box SQL
index c36f0e577b0f76bdee623118065675fd678b5575..e6de0522146fe381770662f78fad11542442ac7b 100644 (file)
@@ -1,7 +1,6 @@
 <?php
        if (file_exists(getenv('NOMINATIM_SETTINGS')))
        {
-               echo 'Using local config: '.getenv('NOMINATIM_SETTINGS');
                require_once(getenv('NOMINATIM_SETTINGS'));
        }
 
index 482e95981cc04b7aab021eb82e979c9e950727a9..07d5bcf370c60a1e1fe3078480ca9857406f3df6 100644 (file)
        }
 
 
-       function getPreferredLanguages()
+       function getPreferredLanguages($sLangString=false)
        {
-               // If we have been provided the value in $_GET it overrides browser value
-               if (isset($_GET['accept-language']) && $_GET['accept-language'])
+               if (!$sLangString)
                {
-                       $_SERVER["HTTP_ACCEPT_LANGUAGE"] = $_GET['accept-language'];
+                       // If we have been provided the value in $_GET it overrides browser value
+                       if (isset($_GET['accept-language']) && $_GET['accept-language'])
+                       {
+                               $_SERVER["HTTP_ACCEPT_LANGUAGE"] = $_GET['accept-language'];
+                               $sLangString = $_GET['accept-language'];
+                       }
+                       else if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
+                       {
+                               $sLangString = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
+                       }
                }
 
                $aLanguages = array();
-               if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
+               if ($sLangString)
                {
-                       if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $aLanguagesParse, PREG_SET_ORDER))
+                       if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER))
                        {
                                foreach($aLanguagesParse as $iLang => $aLanguage)
                                {
diff --git a/utils/query.php b/utils/query.php
new file mode 100755 (executable)
index 0000000..b3fdb26
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/php -Cq
+<?php
+
+    require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
+    require_once(CONST_BasePath.'/lib/Geocode.php');
+    ini_set('memory_limit', '800M');
+
+       $aCMDOptions = array(
+               "Query database from command line. Returns search result as JSON.",
+               array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
+               array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
+               array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
+
+        array('search', '', 0, 1, 1, 1, 'string', 'Search for given term or coordinate'),
+
+        array('accept-language', '', 0, 1, 1, 1, 'string', 'Preferred language order for showing search results'),
+        array('bounded', '', 0, 1, 0, 0, 'bool', 'Restrict results to given viewbox'),
+        array('nodedupe', '', 0, 1, 0, 0, 'bool', 'Do not remove duplicate results'),
+        array('limit', '', 0, 1, 1, 1, 'int', 'Maximum number of results returned (default: 10)'),
+        array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'),
+        array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'),
+        array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'),
+        array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box')
+    );
+    getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
+
+    $oDB =& getDB();
+
+    if (isset($aCMDResult['search']) && $aCMDResult['search'])
+    {
+        if (isset($aCMDResult['bounded'])) $aCMDResult['bounded'] = 'true';
+        if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
+
+        $oGeocode =& new Geocode($oDB);
+        if (isset($aCMDResult['accept-language']) && $aCMDResult['accept-language'])
+            $oGeocode->setLanguagePreference(getPreferredLanguages($aCMDResult['accept-language']));
+        else
+            $oGeocode->setLanguagePreference(getPreferredLanguages());
+        $oGeocode->loadParamArray($aCMDResult);
+        $oGeocode->setQuery($aCMDResult['search']);
+
+        $aSearchResults = $oGeocode->lookup();
+
+        if (version_compare(phpversion(), "5.4.0", '<'))
+            echo json_encode($aSearchResults);
+        else
+            echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
+    }
+    else
+    {
+        showUsage($aCMDOptions, true);
+    }
+    
+
+
index e85c33697fa66554a7bb532aadf3ff3001cadedb..a3a926fd951f440c343857884bed77937b0bb6e5 100755 (executable)
@@ -3,7 +3,7 @@
 
        require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
        require_once(CONST_BasePath.'/lib/log.php');
-        require_once(CONST_BasePath.'/lib/Geocode.php');
+       require_once(CONST_BasePath.'/lib/Geocode.php');
 
        ini_set('memory_limit', '200M');
 
        if (isset($aLangPrefOrder['name:pl'])) $oGeocode->setReverseInPlan(true);
     */
 
-       function loadParamsToGeocode($oGeocode, $aParams, $bBatch = false)
-       {
-               if (isset($aParams['addressdetails'])) $oGeocode->setIncludeAddressDetails((bool)$aParams['addressdetails']);
-               if (isset($aParams['bounded'])) $oGeocode->setBounded((bool)$aParams['bounded']);
-               if (isset($aParams['dedupe'])) $oGeocode->setDedupe((bool)$aParams['dedupe']);
-
-               if (isset($aParams['limit'])) $oGeocode->setLimit((int)$aParams['limit']);
-               if (isset($aParams['offset'])) $oGeocode->setOffset((int)$aParams['offset']);
-
-               if (isset($aParams['fallback'])) $oGeocode->setFallback((int)$aParams['fallback']);
-
-               // List of excluded Place IDs - used for more acurate pageing
-               if (isset($aParams['exclude_place_ids']) && $aParams['exclude_place_ids'])
-               {
-                       foreach(explode(',',$aParams['exclude_place_ids']) as $iExcludedPlaceID)
-                       {
-                               $iExcludedPlaceID = (int)$iExcludedPlaceID;
-                               if ($iExcludedPlaceID) $aExcludePlaceIDs[$iExcludedPlaceID] = $iExcludedPlaceID;
-                       }
-                       $oGeocode->setExcludedPlaceIds($aExcludePlaceIDs);
-               }
-
-               // Only certain ranks of feature
-               if (isset($aParams['featureType'])) $oGeocode->setFeatureType($aParams['featureType']);
-               if (isset($aParams['featuretype'])) $oGeocode->setFeatureType($aParams['featuretype']);
-
-               // Country code list
-               if (isset($aParams['countrycodes']))
-               {
-                       $aCountryCodes = array();
-                       foreach(explode(',',$aParams['countrycodes']) as $sCountryCode)
-                       {
-                               if (preg_match('/^[a-zA-Z][a-zA-Z]$/', $sCountryCode))
-                               {
-                                       $aCountryCodes[] = strtolower($sCountryCode);
-                               }
-                       }
-                       $oGeocode->setCountryCodesList($aCountryCodes);
-               }
-
-               if (isset($aParams['viewboxlbrt']) && $aParams['viewboxlbrt'])
-               {
-                       $aCoOrdinatesLBRT = explode(',',$aParams['viewboxlbrt']);
-                       $oGeocode->setViewBox($aCoOrdinatesLBRT[0], $aCoOrdinatesLBRT[1], $aCoOrdinatesLBRT[2], $aCoOrdinatesLBRT[3]);
-               }
-               else if (isset($aParams['viewbox']) && $aParams['viewbox'])
-               {
-                       $aCoOrdinatesLTRB = explode(',',$aParams['viewbox']);
-                       $oGeocode->setViewBox($aCoOrdinatesLTRB[0], $aCoOrdinatesLTRB[3], $aCoOrdinatesLTRB[2], $aCoOrdinatesLTRB[1]);
-               }
-
-               if (isset($aParams['route']) && $aParams['route'] && isset($aParams['routewidth']) && $aParams['routewidth'])
-               {
-                       $aPoints = explode(',',$aParams['route']);
-                       if (sizeof($aPoints) % 2 != 0)
-                       {
-                               userError("Uneven number of points");
-                               exit;
-                       }
-                       $fPrevCoord = false;
-                       $aRoute = array();
-                       foreach($aPoints as $i => $fPoint)
-                       {
-                               if ($i%2)
-                               {
-                                       $aRoute[] = array((float)$fPoint, $fPrevCoord);
-                               }
-                               else
-                               {
-                                       $fPrevCoord = (float)$fPoint;
-                               }
-                       }
-                       $oGeocode->setRoute($aRoute);
-               }
-
-               // Search query
-               $sQuery = (isset($aParams['q'])?trim($aParams['q']):'');
-               if (!$sQuery && !$bBatch && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/')
-               {
-                       $sQuery = substr($_SERVER['PATH_INFO'], 1);
-
-                       // reverse order of '/' separated string
-                       $aPhrases = explode('/', $sQuery);
-                       $aPhrases = array_reverse($aPhrases);
-                       $sQuery = join(', ',$aPhrases);
-               }
-               if (!$sQuery)
-               {
-                       $oGeocode->setStructuredQuery(@$aParams['amenity'], @$aParams['street'], @$aParams['city'], @$aParams['county'], @$aParams['state'], @$aParams['country'], @$aParams['postalcode']);
-                       $oGeocode->setReverseInPlan(false);
-               }
-               else
-               {
-                       $oGeocode->setQuery($sQuery);
-               }
-
-       }
-
        // Format for output
        $sOutputFormat = 'html';
        if (isset($_GET['format']) && ($_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' ||  $_GET['format'] == 'jsonv2'))
                $oGeocode->setIncludePolygonAsSVG($bAsSVG);
        }
 
-       loadParamsToGeocode($oGeocode, $_GET, false);
+       $oGeocode->loadParamArray($_GET);
 
        if (CONST_Search_BatchMode && isset($_GET['batch']))
        {
                foreach($aBatch as $aBatchParams)
                {
                        $oBatchGeocode = clone $oGeocode;
-                       loadParamsToGeocode($oBatchGeocode, $aBatchParams, true);
+                       $oBatchGeocode->loadParamArray($aBatchParams);
+                       $oBatchGeocode->setQueryFromParams($aBatchParams);
                        $aSearchResults = $oBatchGeocode->lookup();
                        $aBatchResults[] = $aSearchResults;
                }
                include(CONST_BasePath.'/lib/template/search-batch-json.php');
                exit;
-       }
+       } else {
+        if (!(isset($_GET['q']) && $_GET['q']) && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/')
+        {
+            $sQuery = substr($_SERVER['PATH_INFO'], 1);
+
+            // reverse order of '/' separated string
+            $aPhrases = explode('/', $sQuery);
+            $aPhrases = array_reverse($aPhrases);
+            $sQuery = join(', ',$aPhrases);
+            $oGeocode->setQuery($sQuery);
+        }
+        else
+        {
+            $oGeocode->setQueryFromParams($_GET);
+        }
+
+    }
 
        $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);