3  * SPDX-License-Identifier: GPL-2.0-only
 
   5  * This file is part of Nominatim. (https://nominatim.org)
 
   7  * Copyright (C) 2022 by the Nominatim developer community.
 
   8  * For a full list of authors see the git log.
 
  11 namespace Nominatim\Token;
 
  18     /// Database word id, if available.
 
  20     /// Two-letter country code (lower-cased).
 
  21     private $sCountryCode;
 
  23     public function __construct($iId, $sCountryCode)
 
  26         $this->sCountryCode = $sCountryCode;
 
  29     public function getId()
 
  35      * Check if the token can be added to the given search.
 
  36      * Derive new searches by adding this token to an existing search.
 
  38      * @param object  $oSearch      Partial search description derived so far.
 
  39      * @param object  $oPosition    Description of the token position within
 
  42      * @return True if the token is compatible with the search configuration
 
  45     public function isExtendable($oSearch, $oPosition)
 
  47         return !$oSearch->hasCountry()
 
  48                && $oPosition->maybePhrase('country')
 
  49                && $oSearch->getContext()->isCountryApplicable($this->sCountryCode);
 
  53      * Derive new searches by adding this token to an existing search.
 
  55      * @param object  $oSearch      Partial search description derived so far.
 
  56      * @param object  $oPosition    Description of the token position within
 
  59      * @return SearchDescription[] List of derived search descriptions.
 
  61     public function extendSearch($oSearch, $oPosition)
 
  63         $oNewSearch = $oSearch->clone($oPosition->isLastToken() ? 1 : 6);
 
  64         $oNewSearch->setCountry($this->sCountryCode);
 
  66         return array($oNewSearch);
 
  69     public function debugInfo()
 
  74                 'Info' => $this->sCountryCode
 
  78     public function debugCode()