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');
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;
}
}
-
}
}
}
// Sort and cut
- usort($aNewWordsetSearches, 'bySearchRank');
+ usort($aNewWordsetSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
$aWordsetSearches = array_slice($aNewWordsetSearches, 0, 50);
}
//var_Dump('<hr>',sizeof($aWordsetSearches)); exit;
$aNewPhraseSearches = array_merge($aNewPhraseSearches, $aNewWordsetSearches);
- usort($aNewPhraseSearches, 'bySearchRank');
+ usort($aNewPhraseSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
$aSearchHash = array();
foreach ($aNewPhraseSearches as $iSearch => $aSearch) {
// Revisit searches, drop bad searches and give penalty to unlikely combinations.
$aGroupedSearches = array();
foreach ($aSearches as $oSearch) {
- if (!$oSearch->isValidSearch()) {
+ if (!$oSearch->isValidSearch($this->aCountryCodes)) {
continue;
}
$iRank = $oSearch->addToRank($iGlobalRank);
- if (!isset($aGroupedSearches[$iRank]) {
+ if (!isset($aGroupedSearches[$iRank])) {
$aGroupedSearches[$iRank] = array();
}
$aGroupedSearches[$iRank][] = $oSearch;
$sNormQuery = $this->normTerm($this->sQuery);
$sLanguagePrefArraySQL = getArraySQL(
- array_map("getDBQuoted",
- $this->aLangPrefOrder)
+ array_map("getDBQuoted", $this->aLangPrefOrder)
);
$sCountryCodesSQL = false;
if ($this->aCountryCodes) {
$oNewSearch->setPoiSearch(
Operator::TYPE,
$aSearchTerm['class'],
- $aSearchTerm['type'],
+ $aSearchTerm['type']
);
$aNewSearches[] = $oNewSearch;
}
foreach ($aTokens as $sToken) {
// Unknown single word token with a number - assume it is a house number
- if (!isset($aValidTokens[' '.$sToken]) && strpos($sToken, ' ') === false && preg_match('/[0-9]/', $sToken)) {
- $aValidTokens[' '.$sToken] = array(array('class' => 'place', 'type' => 'house'));
+ if (!isset($aValidTokens[' '.$sToken]) && strpos($sToken, ' ') === false && preg_match('/^[0-9]+$/', $sToken)) {
+ $aValidTokens[' '.$sToken] = array(array('class' => 'place', 'type' => 'house', 'word_token' => ' '.$sToken));
}
}
$this->oDB,
$sCountryCodesSQL,
$bBoundingBoxSearch ? $this->sViewboxSmallSQL : '',
- $sViewboxCentreSQL,
+ $this->sViewboxCentreSQL,
$this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit
);
} elseif ($oSearch->isOperator(Operator::POSTCODE)) {
$aPlaceIDs = $oSearch->queryPostcode(
- $oDB,
+ $this->oDB,
$sCountryCodesSQL,
$this->iLimit
);
$aResult = $oSearch->queryHouseNumber(
$this->oDB,
$aPlaceIDs,
- $this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : ''
+ $this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit
);
if (sizeof($aResult)) {
$searchedHousenumber = $aResult['iHouseNumber'];
- $aPlaceIDs = $aResults['aPlaceIDs'];
+ $aPlaceIDs = $aResult['aPlaceIDs'];
} elseif (!$oSearch->looksLikeFullAddress()) {
$aPlaceIDs = array();
}
$aPlaceIDs = $oSearch->queryPoiByOperator(
$this->oDB,
$aPlaceIDs,
- $this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : ''
+ $this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit
);
}