3 require_once(CONST_BasePath.'/lib/init-website.php');
4 require_once(CONST_BasePath.'/lib/log.php');
5 require_once(CONST_BasePath.'/lib/Geocode.php');
6 require_once(CONST_BasePath.'/lib/output.php');
7 ini_set('memory_limit', '200M');
9 $oDB = new Nominatim\DB();
11 $oParams = new Nominatim\ParameterParser();
13 $oGeocode = new Nominatim\Geocode($oDB);
15 $aLangPrefOrder = $oParams->getPreferredLanguages();
16 $oGeocode->setLanguagePreference($aLangPrefOrder);
18 if (CONST_Search_ReversePlanForAll
19 || isset($aLangPrefOrder['name:de'])
20 || isset($aLangPrefOrder['name:ru'])
21 || isset($aLangPrefOrder['name:ja'])
22 || isset($aLangPrefOrder['name:pl'])
24 $oGeocode->setReverseInPlan(true);
28 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'html');
29 set_exception_handler_by_format($sOutputFormat);
31 $sForcedGeometry = ($sOutputFormat == 'html') ? 'geojson' : null;
32 $oGeocode->loadParamArray($oParams, $sForcedGeometry);
34 if (CONST_Search_BatchMode && isset($_GET['batch'])) {
35 $aBatch = json_decode($_GET['batch'], true);
36 $aBatchResults = array();
37 foreach ($aBatch as $aBatchParams) {
38 $oBatchGeocode = clone $oGeocode;
39 $oBatchParams = new Nominatim\ParameterParser($aBatchParams);
40 $oBatchGeocode->loadParamArray($oBatchParams);
41 $oBatchGeocode->setQueryFromParams($oBatchParams);
42 $aSearchResults = $oBatchGeocode->lookup();
43 $aBatchResults[] = $aSearchResults;
45 include(CONST_BasePath.'/lib/template/search-batch-json.php');
49 $oGeocode->setQueryFromParams($oParams);
51 if (!$oGeocode->getQueryString()
52 && isset($_SERVER['PATH_INFO'])
53 && $_SERVER['PATH_INFO'][0] == '/'
55 $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
57 // reverse order of '/' separated string
58 $aPhrases = explode('/', $sQuery);
59 $aPhrases = array_reverse($aPhrases);
60 $sQuery = join(', ', $aPhrases);
61 $oGeocode->setQuery($sQuery);
64 $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
66 $aSearchResults = $oGeocode->lookup();
68 if ($sOutputFormat=='html') {
69 $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
71 logEnd($oDB, $hLog, count($aSearchResults));
73 $sQuery = $oGeocode->getQueryString();
75 $aMoreParams = $oGeocode->getMoreUrlParams();
76 if ($sOutputFormat != 'html') $aMoreParams['format'] = $sOutputFormat;
77 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
78 $aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
80 $sMoreURL = CONST_Website_BaseURL.'search.php?'.http_build_query($aMoreParams);
82 if (CONST_Debug) exit;
84 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
85 include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php');