3 namespace Nominatim\Token;
10 /// Database word id, if available.
12 /// Full nomralized postcode (upper cased).
14 // Optional country code the postcode belongs to (currently unused).
15 private $sCountryCode;
17 public function __construct($iId, $sPostcode, $sCountryCode = '')
20 $this->sPostcode = $sPostcode;
21 $this->sCountryCode = empty($sCountryCode) ? '' : $sCountryCode;
24 public function getId()
30 * Derive new searches by adding this token to an existing search.
32 * @param object $oSearch Partial search description derived so far.
33 * @param object $oPosition Description of the token position within
36 * @return SearchDescription[] List of derived search descriptions.
38 public function extendSearch($oSearch, $oPosition)
40 $aNewSearches = array();
42 if ($oSearch->hasPostcode() || !$oPosition->maybePhrase('postalcode')) {
46 // If we have structured search or this is the first term,
47 // make the postcode the primary search element.
48 if ($oSearch->hasOperator(\Nominatim\Operator::NONE) && $oPosition->isFirstToken()) {
49 $oNewSearch = $oSearch->clone(1);
50 $oNewSearch->setPostcodeAsName($this->iId, $this->sPostcode);
52 $aNewSearches[] = $oNewSearch;
55 // If we have a structured search or this is not the first term,
56 // add the postcode as an addendum.
57 if (!$oSearch->hasOperator(\Nominatim\Operator::POSTCODE)
58 && ($oPosition->isPhrase('postalcode') || $oSearch->hasName())
61 if (strlen($this->sPostcode) < 4) {
62 $iPenalty += 4 - strlen($this->sPostcode);
64 $oNewSearch = $oSearch->clone($iPenalty);
65 $oNewSearch->setPostcode($this->sPostcode);
67 $aNewSearches[] = $oNewSearch;
73 public function debugInfo()
78 'Info' => $this->sPostcode.'('.$this->sCountryCode.')'
82 public function debugCode()