]> git.openstreetmap.org Git - nominatim.git/blob - website/search.php
README: tiny markdown syntax error
[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 =& getDB();
10 $oParams = new Nominatim\ParameterParser();
11
12 $oGeocode = new Nominatim\Geocode($oDB);
13
14 $aLangPrefOrder = $oParams->getPreferredLanguages();
15 $oGeocode->setLanguagePreference($aLangPrefOrder);
16
17 if (CONST_Search_ReversePlanForAll
18     || isset($aLangPrefOrder['name:de'])
19     || isset($aLangPrefOrder['name:ru'])
20     || isset($aLangPrefOrder['name:ja'])
21     || isset($aLangPrefOrder['name:pl'])
22 ) {
23     $oGeocode->setReverseInPlan(true);
24 }
25
26 // Format for output
27 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'html');
28 set_exception_handler_by_format($sOutputFormat);
29
30 $sForcedGeometry = ($sOutputFormat == 'html') ? 'geojson' : null;
31 $oGeocode->loadParamArray($oParams, $sForcedGeometry);
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     && $_SERVER['PATH_INFO'][0] == '/'
53 ) {
54     $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
55
56     // reverse order of '/' separated string
57     $aPhrases = explode('/', $sQuery);
58     $aPhrases = array_reverse($aPhrases);
59     $sQuery = join(', ', $aPhrases);
60     $oGeocode->setQuery($sQuery);
61 }
62
63 $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
64
65 $aSearchResults = $oGeocode->lookup();
66
67 if ($sOutputFormat=='html') {
68     $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
69 }
70 logEnd($oDB, $hLog, count($aSearchResults));
71
72 $sQuery = $oGeocode->getQueryString();
73
74 $aMoreParams = $oGeocode->getMoreUrlParams();
75 if ($sOutputFormat != 'html') $aMoreParams['format'] = $sOutputFormat;
76 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
77     $aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
78 }
79 $sMoreURL = CONST_Website_BaseURL.'search.php?'.http_build_query($aMoreParams);
80
81 if (CONST_Debug) exit;
82
83 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
84 include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php');