mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-23 05:35:13 +03:00
remove country restriction from tokenizer
Restricting tokens due to the search context is better done in the generic search part instead of repeating the same test in every tokenizer implementation.
This commit is contained in:
parent
78d11fe628
commit
0fb8eade13
@ -498,7 +498,6 @@ class Geocode
|
||||
if ($this->aCountryCodes) {
|
||||
$oCtx->setCountryList($this->aCountryCodes);
|
||||
}
|
||||
$this->oTokenizer->setCountryRestriction($this->aCountryCodes);
|
||||
|
||||
Debug::newSection('Query Preprocessing');
|
||||
|
||||
|
@ -28,6 +28,8 @@ class SearchContext
|
||||
public $sqlViewboxLarge = '';
|
||||
/// Reference along a route (as SQL).
|
||||
public $sqlViewboxCentre = '';
|
||||
/// List of countries to restrict search to (as array).
|
||||
public $aCountryList = null;
|
||||
/// List of countries to restrict search to (as SQL).
|
||||
public $sqlCountryList = '';
|
||||
/// List of place IDs to exclude (as SQL).
|
||||
@ -187,6 +189,7 @@ class SearchContext
|
||||
public function setCountryList($aCountries)
|
||||
{
|
||||
$this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
|
||||
$this->aCountryList = $aCountries;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,6 +282,19 @@ class SearchContext
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given country is covered by the search context.
|
||||
*
|
||||
* @param string $sCountryCode Country code of the country to check.
|
||||
*
|
||||
* @return True, if no country code restrictions are set or the
|
||||
* country is included in the country list.
|
||||
*/
|
||||
public function isCountryApplicable($sCountryCode)
|
||||
{
|
||||
return $this->aCountryList === null || in_array($sCountryCode, $this->aCountryList);
|
||||
}
|
||||
|
||||
public function debugInfo()
|
||||
{
|
||||
return array(
|
||||
|
@ -36,7 +36,9 @@ class Country
|
||||
*/
|
||||
public function isExtendable($oSearch, $oPosition)
|
||||
{
|
||||
return !$oSearch->hasCountry() && $oPosition->maybePhrase('country');
|
||||
return !$oSearch->hasCountry()
|
||||
&& $oPosition->maybePhrase('country')
|
||||
&& $oSearch->getContext()->isCountryApplicable($this->sCountryCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,6 @@ class Tokenizer
|
||||
|
||||
private $oNormalizer;
|
||||
private $oTransliterator;
|
||||
private $aCountryRestriction;
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
@ -30,12 +29,6 @@ class Tokenizer
|
||||
}
|
||||
|
||||
|
||||
public function setCountryRestriction($aCountries)
|
||||
{
|
||||
$this->aCountryRestriction = $aCountries;
|
||||
}
|
||||
|
||||
|
||||
public function normalizeString($sTerm)
|
||||
{
|
||||
if ($this->oNormalizer === null) {
|
||||
@ -162,10 +155,7 @@ class Tokenizer
|
||||
|
||||
switch ($aWord['type']) {
|
||||
case 'C': // country name tokens
|
||||
if ($aWord['word'] !== null
|
||||
&& (!$this->aCountryRestriction
|
||||
|| in_array($aWord['word'], $this->aCountryRestriction))
|
||||
) {
|
||||
if ($aWord['word'] !== null) {
|
||||
$oValidTokens->addToken(
|
||||
$sTok,
|
||||
new Token\Country($iId, $aWord['word'])
|
||||
|
@ -7,7 +7,6 @@ class Tokenizer
|
||||
private $oDB;
|
||||
|
||||
private $oNormalizer = null;
|
||||
private $aCountryRestriction = null;
|
||||
|
||||
public function __construct(&$oDB)
|
||||
{
|
||||
@ -37,12 +36,6 @@ class Tokenizer
|
||||
}
|
||||
|
||||
|
||||
public function setCountryRestriction($aCountries)
|
||||
{
|
||||
$this->aCountryRestriction = $aCountries;
|
||||
}
|
||||
|
||||
|
||||
public function normalizeString($sTerm)
|
||||
{
|
||||
if ($this->oNormalizer === null) {
|
||||
@ -206,12 +199,7 @@ class Tokenizer
|
||||
);
|
||||
}
|
||||
} elseif ($aWord['country_code']) {
|
||||
// Filter country tokens that do not match restricted countries.
|
||||
if (!$this->aCountryRestriction
|
||||
|| in_array($aWord['country_code'], $this->aCountryRestriction)
|
||||
) {
|
||||
$oToken = new Token\Country($iId, $aWord['country_code']);
|
||||
}
|
||||
$oToken = new Token\Country($iId, $aWord['country_code']);
|
||||
} elseif ($aWord['word_token'][0] == ' ') {
|
||||
$oToken = new Token\Word(
|
||||
$iId,
|
||||
|
Loading…
Reference in New Issue
Block a user