]> git.openstreetmap.org Git - nominatim.git/blob - utils/query.php
replace database abstraction DB with PDO
[nominatim.git] / utils / query.php
1 <?php
2
3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4 require_once(CONST_BasePath.'/lib/Geocode.php');
5 require_once(CONST_BasePath.'/lib/ParameterParser.php');
6 ini_set('memory_limit', '800M');
7
8 $aCMDOptions
9 = array(
10    'Query database from command line. Returns search result as JSON.',
11    array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
12    array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
13    array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
14
15    array('search', '', 0, 1, 1, 1, 'string', 'Search for given term or coordinate'),
16
17    array('accept-language', '', 0, 1, 1, 1, 'string', 'Preferred language order for showing search results'),
18    array('bounded', '', 0, 1, 0, 0, 'bool', 'Restrict results to given viewbox'),
19    array('nodedupe', '', 0, 1, 0, 0, 'bool', 'Do not remove duplicate results'),
20    array('limit', '', 0, 1, 1, 1, 'int', 'Maximum number of results returned (default: 10)'),
21    array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'),
22    array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'),
23    array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'),
24    array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box')
25   );
26 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
27
28 $oDB = new Nominatim\DB;
29 $oDB->connect();
30
31 $oParams = new Nominatim\ParameterParser($aCMDResult);
32
33 if ($oParams->getBool('search')) {
34     if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
35
36     $oGeocode = new Nominatim\Geocode($oDB);
37
38     $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false));
39     $oGeocode->loadParamArray($oParams);
40     $oGeocode->setQuery($aCMDResult['search']);
41
42     $aSearchResults = $oGeocode->lookup();
43
44     echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
45 } else {
46     showUsage($aCMDOptions, true);
47 }