X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d7c469d94e088232d9be45a51ebf76f00f7e1921..d586b95ff11a45ab6223e83e1b0540f1db87b325:/utils/query.php diff --git a/utils/query.php b/utils/query.php old mode 100755 new mode 100644 index a3f51f74..429b30ff --- a/utils/query.php +++ b/utils/query.php @@ -1,55 +1,92 @@ -#!/usr/bin/php -Cq getBool('search')) - { - if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; +loadSettings($aCMDResult['project-dir'] ?? getcwd()); - $oGeocode = new Geocode($oDB); +@define('CONST_Database_DSN', getSetting('DATABASE_DSN')); +@define('CONST_Default_Language', getSetting('DEFAULT_LANGUAGE', false)); +@define('CONST_Log_DB', getSettingBool('LOG_DB')); +@define('CONST_Log_File', getSetting('LOG_FILE', false)); +@define('CONST_Max_Word_Frequency', getSetting('MAX_WORD_FREQUENCY')); +@define('CONST_NoAccessControl', getSettingBool('CORS_NOACCESSCONTROL')); +@define('CONST_Places_Max_ID_count', getSetting('LOOKUP_MAX_COUNT')); +@define('CONST_PolygonOutput_MaximumTypes', getSetting('POLYGON_OUTPUT_MAX_TYPES')); +@define('CONST_Search_BatchMode', getSettingBool('SEARCH_BATCH_MODE')); +@define('CONST_Search_NameOnlySearchFrequencyThreshold', getSetting('SEARCH_NAME_ONLY_THRESHOLD')); +@define('CONST_Term_Normalization_Rules', getSetting('TERM_NORMALIZATION')); +@define('CONST_Use_Aux_Location_data', getSettingBool('USE_AUX_LOCATION_DATA')); +@define('CONST_Use_US_Tiger_Data', getSettingBool('USE_US_TIGER_DATA')); +@define('CONST_MapIcon_URL', getSetting('MAPICON_URL', false)); - $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false)); - $oGeocode->loadParamArray($oParams); - $oGeocode->setQuery($aCMDResult['search']); - $aSearchResults = $oGeocode->lookup(); +$oDB = new Nominatim\DB; +$oDB->connect(); - 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); - } +if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; +$oParams = new Nominatim\ParameterParser($aCMDResult); +$aSearchParams = array( + 'search', + 'amenity', + 'street', + 'city', + 'county', + 'state', + 'country', + 'postalcode' + ); +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";