namespace Nominatim;
-require_once(CONST_BasePath.'/lib/NearPoint.php');
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
require_once(CONST_BasePath.'/lib/SearchDescription.php');
+require_once(CONST_BasePath.'/lib/SearchContext.php');
class Geocode
{
$this->aAddressRankList = array();
$this->aStructuredQuery = array();
- $this->sAllowedTypesSQLList = False;
+ $this->sAllowedTypesSQLList = false;
$this->loadStructuredAddressElement($sAmenity, 'amenity', 26, 30, false);
$this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
if (sizeof($aPlaceIDs) == 0) return array();
$sLanguagePrefArraySQL = getArraySQL(
- array_map("getDBQuoted",
- $this->aLangPrefOrder)
+ array_map("getDBQuoted", $this->aLangPrefOrder)
);
// Get the details for display (is this a redundant extra step?)
// If the token is valid
if (isset($aValidTokens[' '.$sToken])) {
- // Recheck if the original word shows up in the query.
- $bWordInQuery = false;
- if (isset($aSearchTerm['word']) && $aSearchTerm['word']) {
- $bWordInQuery = $this->normTerm($aSearchTerm['word']) !== false;
- }
foreach ($aValidTokens[' '.$sToken] as $aSearchTerm) {
+ // Recheck if the original word shows up in the query.
+ $bWordInQuery = false;
+ if (isset($aSearchTerm['word']) && $aSearchTerm['word']) {
+ $bWordInQuery = strpos(
+ $sNormQuery,
+ $this->normTerm($aSearchTerm['word'])
+ ) !== false;
+ }
$aNewSearches = $oCurrentSearch->extendWithFullTerm(
$aSearchTerm,
$bWordInQuery,
$aNewWordsetSearches[] = $oSearch;
}
}
-
}
}
}
{
if (!$this->sQuery && !$this->aStructuredQuery) return array();
+ $oCtx = new SearchContext();
+
$sNormQuery = $this->normTerm($this->sQuery);
$sLanguagePrefArraySQL = getArraySQL(
- array_map("getDBQuoted",
- $this->aLangPrefOrder)
+ array_map("getDBQuoted", $this->aLangPrefOrder)
);
$sCountryCodesSQL = false;
if ($this->aCountryCodes) {
}
// Do we have anything that looks like a lat/lon pair?
- $oNearPoint = false;
- if ($aLooksLike = NearPoint::extractFromQuery($sQuery)) {
- $oNearPoint = $aLooksLike['pt'];
- $sQuery = $aLooksLike['query'];
- }
+ $sQuery = $oCtx->setNearPointFromQuery($sQuery);
$aSearchResults = array();
if ($sQuery || $this->aStructuredQuery) {
// Start with a single blank search
- $aSearches = array(new SearchDescription());
-
- if ($oNearPoint) {
- $aSearches[0]->setNear($oNearPoint);
- }
+ $aSearches = array(new SearchDescription($oCtx));
if ($sQuery) {
$sQuery = $aSearches[0]->extractKeyValuePairs($sQuery);
}
} elseif (!$oSearch->isNamedSearch()) {
// looking for a POI in a geographic area
- if (!$bBoundingBoxSearch && !$oSearch->isNearSearch()) {
+ if (!$bBoundingBoxSearch && !$oCtx->hasNearPoint()) {
continue;
}
);
} elseif ($oSearch->isOperator(Operator::POSTCODE)) {
$aPlaceIDs = $oSearch->queryPostcode(
- $oDB,
+ $this->oDB,
$sCountryCodesSQL,
$this->iLimit
);
$oReverse = new ReverseGeocode($this->oDB);
$oReverse->setZoom(18);
- $aLookup = $oReverse->lookup(
- $oNearPoint->lat(),
- $oNearPoint->lon(),
- false
- );
+ $aLookup = $oReverse->lookupPoint($oCtx->sqlNear, false);
if (CONST_Debug) var_dump("Reverse search", $aLookup);