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 * Derive new searches by adding this token to an existing search.
29 * @param object $oSearch Partial search description derived so far.
30 * @param object $oPosition Description of the token position within
33 * @return SearchDescription[] List of derived search descriptions.
35 public function extendSearch($oSearch, $oPosition)
37 $aNewSearches = array();
39 if ($oSearch->hasHousenumber()
40 || $oSearch->hasOperator(\Nominatim\Operator::POSTCODE)
41 || !$oPosition->maybePhrase('street')
46 // sanity check: if the housenumber is not mainly made
47 // up of numbers, add a penalty
49 if (preg_match('/\\d/', $this->sToken) === 0
50 || preg_match_all('/[^0-9]/', $this->sToken, $aMatches) > 2) {
53 if (!$oSearch->hasOperator(\Nominatim\Operator::NONE)) {
56 if (empty($this->iId)) {
59 // also must not appear in the middle of the address
60 if ($oSearch->hasAddress() || $oSearch->hasPostcode()) {
64 $oNewSearch = $oSearch->clone($iSearchCost);
65 $oNewSearch->setHousenumber($this->sToken);
66 $aNewSearches[] = $oNewSearch;
68 // Housenumbers may appear in the name when the place has its own
70 if ($this->iId !== null
71 && ($oSearch->getNamePhrase() >= 0 || !$oSearch->hasName())
72 && !$oSearch->hasAddress()
74 $oNewSearch = $oSearch->clone($iSearchCost);
75 $oNewSearch->setHousenumberAsName($this->iId);
77 $aNewSearches[] = $oNewSearch;
84 public function debugInfo()
88 'Type' => 'house number',
89 'Info' => array('nr' => $this->sToken)
93 public function debugCode()