]> git.openstreetmap.org Git - nominatim.git/blob - website/search.php
remove HTML output and UI elements
[nominatim.git] / website / search.php
1 <?php
2
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');
8
9 $oDB = new Nominatim\DB();
10 $oDB->connect();
11 $oParams = new Nominatim\ParameterParser();
12
13 $oGeocode = new Nominatim\Geocode($oDB);
14
15 $aLangPrefOrder = $oParams->getPreferredLanguages();
16 $oGeocode->setLanguagePreference($aLangPrefOrder);
17
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'])
23 ) {
24     $oGeocode->setReverseInPlan(true);
25 }
26
27 // Format for output
28 $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2');
29 set_exception_handler_by_format($sOutputFormat);
30
31 $oGeocode->loadParamArray($oParams, null);
32
33 if (CONST_Search_BatchMode && isset($_GET['batch'])) {
34     $aBatch = json_decode($_GET['batch'], true);
35     $aBatchResults = array();
36     foreach ($aBatch as $aBatchParams) {
37         $oBatchGeocode = clone $oGeocode;
38         $oBatchParams = new Nominatim\ParameterParser($aBatchParams);
39         $oBatchGeocode->loadParamArray($oBatchParams);
40         $oBatchGeocode->setQueryFromParams($oBatchParams);
41         $aSearchResults = $oBatchGeocode->lookup();
42         $aBatchResults[] = $aSearchResults;
43     }
44     include(CONST_BasePath.'/lib/template/search-batch-json.php');
45     exit;
46 }
47
48 $oGeocode->setQueryFromParams($oParams);
49
50 if (!$oGeocode->getQueryString()
51     && isset($_SERVER['PATH_INFO'])
52     && strlen($_SERVER['PATH_INFO']) > 0
53     && $_SERVER['PATH_INFO'][0] == '/'
54 ) {
55     $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
56
57     // reverse order of '/' separated string
58     $aPhrases = explode('/', $sQuery);
59     $aPhrases = array_reverse($aPhrases);
60     $sQuery = join(', ', $aPhrases);
61     $oGeocode->setQuery($sQuery);
62 }
63
64 $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
65
66 $aSearchResults = $oGeocode->lookup();
67
68 logEnd($oDB, $hLog, count($aSearchResults));
69
70 $sQuery = $oGeocode->getQueryString();
71
72 $aMoreParams = $oGeocode->getMoreUrlParams();
73 $aMoreParams['format'] = $sOutputFormat;
74 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
75     $aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
76 }
77 $sMoreURL = CONST_Website_BaseURL.'search.php?'.http_build_query($aMoreParams);
78
79 if (CONST_Debug) exit;
80
81 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
82 include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php');