3 require_once(CONST_LibDir.'/init-website.php');
4 require_once(CONST_LibDir.'/log.php');
5 require_once(CONST_LibDir.'/Geocode.php');
6 require_once(CONST_LibDir.'/output.php');
7 ini_set('memory_limit', '200M');
9 $oDB = new Nominatim\DB(CONST_Database_DSN);
11 $oParams = new Nominatim\ParameterParser();
13 $oGeocode = new Nominatim\Geocode($oDB);
15 $aLangPrefOrder = $oParams->getPreferredLanguages();
16 $oGeocode->setLanguagePreference($aLangPrefOrder);
19 $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2');
20 set_exception_handler_by_format($sOutputFormat);
22 $oGeocode->loadParamArray($oParams, null);
24 if (CONST_Search_BatchMode && isset($_GET['batch'])) {
25 $aBatch = json_decode($_GET['batch'], true);
26 $aBatchResults = array();
27 foreach ($aBatch as $aBatchParams) {
28 $oBatchGeocode = clone $oGeocode;
29 $oBatchParams = new Nominatim\ParameterParser($aBatchParams);
30 $oBatchGeocode->loadParamArray($oBatchParams);
31 $oBatchGeocode->setQueryFromParams($oBatchParams);
32 $aSearchResults = $oBatchGeocode->lookup();
33 $aBatchResults[] = $aSearchResults;
35 include(CONST_LibDir.'/template/search-batch-json.php');
39 $oGeocode->setQueryFromParams($oParams);
41 if (!$oGeocode->getQueryString()
42 && isset($_SERVER['PATH_INFO'])
43 && strlen($_SERVER['PATH_INFO']) > 0
44 && $_SERVER['PATH_INFO'][0] == '/'
46 $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
48 // reverse order of '/' separated string
49 $aPhrases = explode('/', $sQuery);
50 $aPhrases = array_reverse($aPhrases);
51 $sQuery = join(', ', $aPhrases);
52 $oGeocode->setQuery($sQuery);
55 $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
57 // Ignore requests from a faulty app.
58 if ($oGeocode->getQueryString() === '-1,-1') {
59 $aSearchResults = array();
61 $aSearchResults = $oGeocode->lookup();
64 logEnd($oDB, $hLog, count($aSearchResults));
66 $sQuery = $oGeocode->getQueryString();
68 $aMoreParams = $oGeocode->getMoreUrlParams();
69 $aMoreParams['format'] = $sOutputFormat;
70 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
71 $aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
74 if (isset($_SERVER['REQUEST_SCHEME'])
75 && isset($_SERVER['HTTP_HOST'])
76 && isset($_SERVER['DOCUMENT_URI'])
78 $sMoreURL = $_SERVER['REQUEST_SCHEME'].'://'
79 .$_SERVER['HTTP_HOST'].$_SERVER['DOCUMENT_URI'].'/?'
80 .http_build_query($aMoreParams);
82 $sMoreURL = '/search.php?'.http_build_query($aMoreParams);
89 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
90 include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php');