3 namespace Nominatim\Token;
6 * A house number token.
10 /// Database word id, if available.
12 /// Normalized house number.
15 public function __construct($iId, $sToken)
18 $this->sToken = $sToken;
21 public function getId()
27 * Check if the token can be added to the given search.
28 * Derive new searches by adding this token to an existing search.
30 * @param object $oSearch Partial search description derived so far.
31 * @param object $oPosition Description of the token position within
34 * @return True if the token is compatible with the search configuration
37 public function isExtendable($oSearch, $oPosition)
39 return !$oSearch->hasHousenumber()
40 && !$oSearch->hasOperator(\Nominatim\Operator::POSTCODE)
41 && $oPosition->maybePhrase('street');
45 * Derive new searches by adding this token to an existing search.
47 * @param object $oSearch Partial search description derived so far.
48 * @param object $oPosition Description of the token position within
51 * @return SearchDescription[] List of derived search descriptions.
53 public function extendSearch($oSearch, $oPosition)
55 $aNewSearches = array();
57 // sanity check: if the housenumber is not mainly made
58 // up of numbers, add a penalty
60 if (preg_match('/\\d/', $this->sToken) === 0
61 || preg_match_all('/[^0-9]/', $this->sToken, $aMatches) > 2) {
62 $iSearchCost += strlen($this->sToken) - 1;
64 if (!$oSearch->hasOperator(\Nominatim\Operator::NONE)) {
67 if (empty($this->iId)) {
70 // also must not appear in the middle of the address
71 if ($oSearch->hasAddress() || $oSearch->hasPostcode()) {
75 $oNewSearch = $oSearch->clone($iSearchCost);
76 $oNewSearch->setHousenumber($this->sToken);
77 $aNewSearches[] = $oNewSearch;
79 // Housenumbers may appear in the name when the place has its own
81 if ($this->iId !== null
82 && ($oSearch->getNamePhrase() >= 0 || !$oSearch->hasName())
83 && !$oSearch->hasAddress()
85 $oNewSearch = $oSearch->clone($iSearchCost);
86 $oNewSearch->setHousenumberAsName($this->iId);
88 $aNewSearches[] = $oNewSearch;
95 public function debugInfo()
99 'Type' => 'house number',
100 'Info' => array('nr' => $this->sToken)
104 public function debugCode()