X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/832547f192904a9ec92e173c27a91e0874fcc757..992d3faac81baa105c92874a412ebf5389c0ca14:/utils/query.php diff --git a/utils/query.php b/utils/query.php old mode 100755 new mode 100644 index 06d7f13b..088c14dd --- a/utils/query.php +++ b/utils/query.php @@ -1,52 +1,76 @@ -#!/usr/bin/php -Cq getBool('search')) -{ - if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; +$oDB = new Nominatim\DB; +$oDB->connect(); - $oGeocode = new Geocode($oDB); +if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; - $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false)); - $oGeocode->loadParamArray($oParams); - $oGeocode->setQuery($aCMDResult['search']); +$oParams = new Nominatim\ParameterParser($aCMDResult); - $aSearchResults = $oGeocode->lookup(); +$aSearchParams = array( + 'search', + 'amenity', + 'street', + 'city', + 'county', + 'state', + 'country', + 'postalcode' + ); - 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 -{ +if (!$oParams->hasSetAny($aSearchParams)) { showUsage($aCMDOptions, true); + return 1; +} + +$oGeocode = new Nominatim\Geocode($oDB); + +$oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false)); +$oGeocode->setReverseInPlan(true); +$oGeocode->loadParamArray($oParams); + +if ($oParams->getBool('search')) { + $oGeocode->setQuery($aCMDResult['search']); +} else { + $oGeocode->setQueryFromParams($oParams); } + +$aSearchResults = $oGeocode->lookup(); + +echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";