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 * 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 !$oPosition->isPhrase('country');
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 // Partial token in Address.
59 if (($oPosition->isPhrase('') || !$oPosition->isFirstPhrase())
60 && $oSearch->hasName()
62 $iSearchCost = $this->bNumberToken ? 2 : 1;
63 if ($this->iSearchNameCount >= CONST_Max_Word_Frequency) {
67 $oNewSearch = $oSearch->clone($iSearchCost);
68 $oNewSearch->addAddressToken(
70 $this->iSearchNameCount < CONST_Max_Word_Frequency
73 $aNewSearches[] = $oNewSearch;
76 // Partial token in Name.
77 if ((!$oSearch->hasPostcode() && !$oSearch->hasAddress())
78 && (!$oSearch->hasName(true)
79 || $oSearch->getNamePhrase() == $oPosition->getPhrase())
82 if (!$oSearch->hasName(true)) {
85 if ($this->bNumberToken) {
89 $oNewSearch = $oSearch->clone($iSearchCost);
90 $oNewSearch->addPartialNameToken(
92 $this->iSearchNameCount < CONST_Max_Word_Frequency,
93 $this->iSearchNameCount > CONST_Search_NameOnlySearchFrequencyThreshold,
94 $oPosition->getPhrase()
97 $aNewSearches[] = $oNewSearch;
100 return $aNewSearches;
104 public function debugInfo()
110 'count' => $this->iSearchNameCount
115 public function debugCode()