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 * Check if the token can be added to the given search.
31 * Derive new searches by adding this token to an existing search.
33 * @param object $oSearch Partial search description derived so far.
34 * @param object $oPosition Description of the token position within
37 * @return True if the token is compatible with the search configuration
40 public function isExtendable($oSearch, $oPosition)
42 return !$oSearch->hasPostcode() && $oPosition->maybePhrase('postalcode');
46 * Derive new searches by adding this token to an existing search.
48 * @param object $oSearch Partial search description derived so far.
49 * @param object $oPosition Description of the token position within
52 * @return SearchDescription[] List of derived search descriptions.
54 public function extendSearch($oSearch, $oPosition)
56 $aNewSearches = array();
58 // If we have structured search or this is the first term,
59 // make the postcode the primary search element.
60 if ($oSearch->hasOperator(\Nominatim\Operator::NONE) && $oPosition->isFirstToken()) {
61 $oNewSearch = $oSearch->clone(1);
62 $oNewSearch->setPostcodeAsName($this->iId, $this->sPostcode);
64 $aNewSearches[] = $oNewSearch;
67 // If we have a structured search or this is not the first term,
68 // add the postcode as an addendum.
69 if (!$oSearch->hasOperator(\Nominatim\Operator::POSTCODE)
70 && ($oPosition->isPhrase('postalcode') || $oSearch->hasName())
73 if (strlen($this->sPostcode) < 4) {
74 $iPenalty += 4 - strlen($this->sPostcode);
76 $oNewSearch = $oSearch->clone($iPenalty);
77 $oNewSearch->setPostcode($this->sPostcode);
79 $aNewSearches[] = $oNewSearch;
85 public function debugInfo()
90 'Info' => $this->sPostcode.'('.$this->sCountryCode.')'
94 public function debugCode()