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.
if ($this->aCountryCodes) {
$oCtx->setCountryList($this->aCountryCodes);
}
if ($this->aCountryCodes) {
$oCtx->setCountryList($this->aCountryCodes);
}
- $this->oTokenizer->setCountryRestriction($this->aCountryCodes);
Debug::newSection('Query Preprocessing');
Debug::newSection('Query Preprocessing');
public $sqlViewboxLarge = '';
/// Reference along a route (as SQL).
public $sqlViewboxCentre = '';
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).
/// List of countries to restrict search to (as SQL).
public $sqlCountryList = '';
/// List of place IDs to exclude (as SQL).
public function setCountryList($aCountries)
{
$this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
public function setCountryList($aCountries)
{
$this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
+ $this->aCountryList = $aCountries;
+ /**
+ * 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(
public function debugInfo()
{
return array(
*/
public function isExtendable($oSearch, $oPosition)
{
*/
public function isExtendable($oSearch, $oPosition)
{
- return !$oSearch->hasCountry() && $oPosition->maybePhrase('country');
+ return !$oSearch->hasCountry()
+ && $oPosition->maybePhrase('country')
+ && $oSearch->getContext()->isCountryApplicable($this->sCountryCode);
private $oNormalizer;
private $oTransliterator;
private $oNormalizer;
private $oTransliterator;
- private $aCountryRestriction;
public function __construct(&$oDB)
{
public function __construct(&$oDB)
{
- public function setCountryRestriction($aCountries)
- {
- $this->aCountryRestriction = $aCountries;
- }
-
-
public function normalizeString($sTerm)
{
if ($this->oNormalizer === null) {
public function normalizeString($sTerm)
{
if ($this->oNormalizer === null) {
switch ($aWord['type']) {
case 'C': // country name tokens
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'])
$oValidTokens->addToken(
$sTok,
new Token\Country($iId, $aWord['word'])
private $oDB;
private $oNormalizer = null;
private $oDB;
private $oNormalizer = null;
- private $aCountryRestriction = null;
public function __construct(&$oDB)
{
public function __construct(&$oDB)
{
- public function setCountryRestriction($aCountries)
- {
- $this->aCountryRestriction = $aCountries;
- }
-
-
public function normalizeString($sTerm)
{
if ($this->oNormalizer === null) {
public function normalizeString($sTerm)
{
if ($this->oNormalizer === null) {
);
}
} elseif ($aWord['country_code']) {
);
}
} 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,
} elseif ($aWord['word_token'][0] == ' ') {
$oToken = new Token\Word(
$iId,