2010-10-27 18:05:42 +04:00
|
|
|
<?php
|
2016-09-04 04:19:48 +03:00
|
|
|
|
2020-12-15 12:09:55 +03:00
|
|
|
require_once(CONST_LibDir.'/init-website.php');
|
|
|
|
require_once(CONST_LibDir.'/log.php');
|
|
|
|
require_once(CONST_LibDir.'/Geocode.php');
|
|
|
|
require_once(CONST_LibDir.'/output.php');
|
2016-09-04 04:19:48 +03:00
|
|
|
ini_set('memory_limit', '200M');
|
|
|
|
|
2020-12-15 17:36:13 +03:00
|
|
|
$oDB = new Nominatim\DB(CONST_Database_DSN);
|
2019-02-24 18:14:36 +03:00
|
|
|
$oDB->connect();
|
2016-09-16 03:27:36 +03:00
|
|
|
$oParams = new Nominatim\ParameterParser();
|
2016-09-04 04:19:48 +03:00
|
|
|
|
2016-09-16 03:27:36 +03:00
|
|
|
$oGeocode = new Nominatim\Geocode($oDB);
|
2016-09-04 04:19:48 +03:00
|
|
|
|
|
|
|
$aLangPrefOrder = $oParams->getPreferredLanguages();
|
|
|
|
$oGeocode->setLanguagePreference($aLangPrefOrder);
|
|
|
|
|
|
|
|
// Format for output
|
2020-10-27 13:05:03 +03:00
|
|
|
$sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2');
|
2018-09-16 18:16:42 +03:00
|
|
|
set_exception_handler_by_format($sOutputFormat);
|
2016-09-04 04:19:48 +03:00
|
|
|
|
2020-10-27 13:05:03 +03:00
|
|
|
$oGeocode->loadParamArray($oParams, null);
|
2016-09-04 04:19:48 +03:00
|
|
|
|
2016-09-08 04:16:22 +03:00
|
|
|
if (CONST_Search_BatchMode && isset($_GET['batch'])) {
|
2016-09-04 04:19:48 +03:00
|
|
|
$aBatch = json_decode($_GET['batch'], true);
|
|
|
|
$aBatchResults = array();
|
2016-09-08 04:16:22 +03:00
|
|
|
foreach ($aBatch as $aBatchParams) {
|
2016-09-04 04:19:48 +03:00
|
|
|
$oBatchGeocode = clone $oGeocode;
|
2016-09-16 03:27:36 +03:00
|
|
|
$oBatchParams = new Nominatim\ParameterParser($aBatchParams);
|
2016-09-04 04:19:48 +03:00
|
|
|
$oBatchGeocode->loadParamArray($oBatchParams);
|
|
|
|
$oBatchGeocode->setQueryFromParams($oBatchParams);
|
|
|
|
$aSearchResults = $oBatchGeocode->lookup();
|
|
|
|
$aBatchResults[] = $aSearchResults;
|
|
|
|
}
|
2020-12-15 12:09:55 +03:00
|
|
|
include(CONST_LibDir.'/template/search-batch-json.php');
|
2016-09-04 04:19:48 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$oGeocode->setQueryFromParams($oParams);
|
|
|
|
|
|
|
|
if (!$oGeocode->getQueryString()
|
2016-09-11 06:22:51 +03:00
|
|
|
&& isset($_SERVER['PATH_INFO'])
|
2019-10-15 09:46:19 +03:00
|
|
|
&& strlen($_SERVER['PATH_INFO']) > 0
|
2016-09-11 06:22:51 +03:00
|
|
|
&& $_SERVER['PATH_INFO'][0] == '/'
|
|
|
|
) {
|
2016-09-04 04:19:48 +03:00
|
|
|
$sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
|
|
|
|
|
|
|
|
// reverse order of '/' separated string
|
|
|
|
$aPhrases = explode('/', $sQuery);
|
|
|
|
$aPhrases = array_reverse($aPhrases);
|
2016-09-11 06:22:51 +03:00
|
|
|
$sQuery = join(', ', $aPhrases);
|
2016-09-04 04:19:48 +03:00
|
|
|
$oGeocode->setQuery($sQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
$hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
|
|
|
|
|
|
|
|
$aSearchResults = $oGeocode->lookup();
|
|
|
|
|
2018-03-22 14:36:24 +03:00
|
|
|
logEnd($oDB, $hLog, count($aSearchResults));
|
2016-09-04 04:19:48 +03:00
|
|
|
|
|
|
|
$sQuery = $oGeocode->getQueryString();
|
2017-03-23 02:16:58 +03:00
|
|
|
|
|
|
|
$aMoreParams = $oGeocode->getMoreUrlParams();
|
2020-10-27 13:05:03 +03:00
|
|
|
$aMoreParams['format'] = $sOutputFormat;
|
2017-10-26 22:21:21 +03:00
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
|
|
|
$aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
2017-03-23 02:16:58 +03:00
|
|
|
}
|
2020-10-27 23:29:35 +03:00
|
|
|
|
|
|
|
if (isset($_SERVER['REQUEST_SCHEME'])
|
|
|
|
&& isset($_SERVER['SERVER_NAME'])
|
|
|
|
&& isset($_SERVER['DOCUMENT_URI'])
|
|
|
|
) {
|
|
|
|
$sMoreURL = $_SERVER['REQUEST_SCHEME'].'://'
|
|
|
|
.$_SERVER['SERVER_NAME'].$_SERVER['DOCUMENT_URI'].'/?'
|
|
|
|
.http_build_query($aMoreParams);
|
|
|
|
} else {
|
|
|
|
$sMoreURL = '/search.php'.http_build_query($aMoreParams);
|
|
|
|
}
|
2016-09-04 04:19:48 +03:00
|
|
|
|
|
|
|
if (CONST_Debug) exit;
|
|
|
|
|
2018-03-18 03:49:26 +03:00
|
|
|
$sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
|
2020-12-15 12:09:55 +03:00
|
|
|
include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php');
|