3 namespace Nominatim\Token;
6 * A standard word token.
10 /// Database word id, if applicable.
12 /// Number of appearances in the database.
13 private $iSearchNameCount;
14 /// True, if the token consists exclusively of digits and spaces.
15 private $bNumberToken;
17 public function __construct($iId, $sToken, $iSearchNameCount)
20 $this->bNumberToken = (bool) preg_match('#^[0-9 ]+$#', $sToken);
21 $this->iSearchNameCount = $iSearchNameCount;
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 if ($oPosition->isPhrase('country')) {
44 $aNewSearches = array();
46 // Partial token in Address.
47 if (($oPosition->isPhrase('') || !$oPosition->isFirstPhrase())
48 && $oSearch->hasName()
50 $iSearchCost = $this->bNumberToken ? 2 : 1;
51 if ($this->iSearchNameCount >= CONST_Max_Word_Frequency) {
55 $oNewSearch = $oSearch->clone($iSearchCost);
56 $oNewSearch->addAddressToken(
58 $this->iSearchNameCount < CONST_Max_Word_Frequency
61 $aNewSearches[] = $oNewSearch;
64 // Partial token in Name.
65 if ((!$oSearch->hasPostcode() && !$oSearch->hasAddress())
66 && (!$oSearch->hasName(true)
67 || $oSearch->getNamePhrase() == $oPosition->getPhrase())
70 if (!$oSearch->hasName(true)) {
73 if ($this->bNumberToken) {
77 $oNewSearch = $oSearch->clone($iSearchCost);
78 $oNewSearch->addPartialNameToken(
80 $this->iSearchNameCount < CONST_Max_Word_Frequency,
81 $oPosition->getPhrase()
84 $aNewSearches[] = $oNewSearch;
91 public function debugInfo()
97 'count' => $this->iSearchNameCount
102 public function debugCode()