X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/38874233816367831c5c30cea0db16d48a3d7016..58c471c627a8893413f9734ff36c3fdc00827e6e:/utils/query.php diff --git a/utils/query.php b/utils/query.php old mode 100755 new mode 100644 index 05875d64..429b30ff --- a/utils/query.php +++ b/utils/query.php @@ -1,20 +1,25 @@ -#!/usr/bin/php -Cq getBool('search')) { - if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; +@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 = new Geocode($oDB); - $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false)); - $oGeocode->loadParamArray($oParams); - $oGeocode->setQuery($aCMDResult['search']); +$oDB = new Nominatim\DB; +$oDB->connect(); - $aSearchResults = $oGeocode->lookup(); +if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; - 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 { +$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";