]> git.openstreetmap.org Git - nominatim.git/blob - utils/query.php
9694bbb95618f17641bda3f4f4cc81c24ab776c4
[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 =& getDB();
29 $oParams = new Nominatim\ParameterParser($aCMDResult);
30
31 if ($oParams->getBool('search')) {
32     if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
33
34     $oGeocode = new Nominatim\Geocode($oDB);
35
36     $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false));
37     $oGeocode->loadParamArray($oParams);
38     $oGeocode->setQuery($aCMDResult['search']);
39
40     $aSearchResults = $oGeocode->lookup();
41
42     echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
43 } else {
44     showUsage($aCMDOptions, true);
45 }