3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 require_once(CONST_LibDir.'/init-website.php');
12 require_once(CONST_LibDir.'/log.php');
13 require_once(CONST_LibDir.'/PlaceLookup.php');
14 require_once(CONST_LibDir.'/output.php');
15 ini_set('memory_limit', '200M');
17 $oParams = new Nominatim\ParameterParser();
20 $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'xml');
21 set_exception_handler_by_format($sOutputFormat);
24 $aLangPrefOrder = $oParams->getPreferredLanguages();
26 $oDB = new Nominatim\DB(CONST_Database_DSN);
29 $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
31 $aSearchResults = array();
32 $aCleanedQueryParts = array();
34 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
35 $oPlaceLookup->loadParamArray($oParams);
36 $oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
38 $aOsmIds = explode(',', $oParams->getString('osm_ids', ''));
40 if (count($aOsmIds) > CONST_Places_Max_ID_count) {
41 userError('Bulk User: Only ' . CONST_Places_Max_ID_count . ' ids are allowed in one request.');
44 foreach ($aOsmIds as $sItem) {
51 $iId = (int) substr($sItem, 1);
52 if ($iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R')) {
53 $aCleanedQueryParts[] = $sType . $iId;
54 $oPlace = $oPlaceLookup->lookupOSMID($sType, $iId);
56 // we want to use the search-* output templates, so we need to fill
57 // $aSearchResults and slightly change the (reverse search) oPlace
60 unset($oResult['aAddress']);
61 if (isset($oPlace['aAddress'])) {
62 $oResult['address'] = $oPlace['aAddress'];
64 if ($sOutputFormat != 'geocodejson') {
65 unset($oResult['langaddress']);
66 $oResult['name'] = $oPlace['langaddress'];
69 $aOutlineResult = $oPlaceLookup->getOutlines(
73 Nominatim\ClassTypes\getDefRadius($oPlace)
76 if ($aOutlineResult) {
77 $oResult = array_merge($oResult, $aOutlineResult);
80 $aSearchResults[] = $oResult;
90 $sXmlRootTag = 'lookupresults';
91 $sQuery = join(',', $aCleanedQueryParts);
92 // we initialize these to avoid warnings in our logfile
95 $aExcludePlaceIDs = array();
98 logEnd($oDB, $hLog, 1);
100 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
101 include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php');