Nominatim/website/search.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2010-10-27 18:05:42 +04:00
<?php
2016-09-04 04:19:48 +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');
$oDB = new Nominatim\DB(CONST_Database_DSN);
$oDB->connect();
$oParams = new Nominatim\ParameterParser();
2016-09-04 04:19:48 +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');
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
if (CONST_Search_BatchMode && isset($_GET['batch'])) {
2016-09-04 04:19:48 +03:00
$aBatch = json_decode($_GET['batch'], true);
$aBatchResults = array();
foreach ($aBatch as $aBatchParams) {
2016-09-04 04:19:48 +03:00
$oBatchGeocode = clone $oGeocode;
$oBatchParams = new Nominatim\ParameterParser($aBatchParams);
2016-09-04 04:19:48 +03:00
$oBatchGeocode->loadParamArray($oBatchParams);
$oBatchGeocode->setQueryFromParams($oBatchParams);
$aSearchResults = $oBatchGeocode->lookup();
$aBatchResults[] = $aSearchResults;
}
include(CONST_LibDir.'/template/search-batch-json.php');
2016-09-04 04:19:48 +03:00
exit;
}
$oGeocode->setQueryFromParams($oParams);
if (!$oGeocode->getQueryString()
&& isset($_SERVER['PATH_INFO'])
&& strlen($_SERVER['PATH_INFO']) > 0
&& $_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);
$sQuery = join(', ', $aPhrases);
2016-09-04 04:19:48 +03:00
$oGeocode->setQuery($sQuery);
}
$hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
$aSearchResults = $oGeocode->lookup();
logEnd($oDB, $hLog, count($aSearchResults));
2016-09-04 04:19:48 +03:00
$sQuery = $oGeocode->getQueryString();
$aMoreParams = $oGeocode->getMoreUrlParams();
2020-10-27 13:05:03 +03:00
$aMoreParams['format'] = $sOutputFormat;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
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;
$sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php');