5 require_once(CONST_LibDir.'/TokenCountry.php');
6 require_once(CONST_LibDir.'/TokenHousenumber.php');
7 require_once(CONST_LibDir.'/TokenPostcode.php');
8 require_once(CONST_LibDir.'/TokenSpecialTerm.php');
9 require_once(CONST_LibDir.'/TokenWord.php');
10 require_once(CONST_LibDir.'/TokenPartial.php');
11 require_once(CONST_LibDir.'/SpecialSearchOperator.php');
14 * Saves information about the tokens that appear in a search query.
16 * Tokens are sorted by their normalized form, the token word. There are different
17 * kinds of tokens, represented by different Token* classes. Note that
18 * tokens do not have a common base class. All tokens need to have a field
19 * with the word id that points to an entry in the `word` database table
20 * but otherwise the information saved about a token can be very different.
24 // List of list of tokens indexed by their word_token.
25 private $aTokens = array();
29 * Return total number of tokens.
33 public function count()
35 return count($this->aTokens);
39 * Check if there are tokens for the given token word.
41 * @param string $sWord Token word to look for.
43 * @return bool True if there is one or more token for the token word.
45 public function contains($sWord)
47 return isset($this->aTokens[$sWord]);
51 * Check if there are partial or full tokens for the given word.
53 * @param string $sWord Token word to look for.
55 * @return bool True if there is one or more token for the token word.
57 public function containsAny($sWord)
59 return isset($this->aTokens[$sWord]);
63 * Get the list of tokens for the given token word.
65 * @param string $sWord Token word to look for.
67 * @return object[] Array of tokens for the given token word or an
68 * empty array if no tokens could be found.
70 public function get($sWord)
72 return isset($this->aTokens[$sWord]) ? $this->aTokens[$sWord] : array();
75 public function getFullWordIDs()
79 foreach ($this->aTokens as $aTokenList) {
80 foreach ($aTokenList as $oToken) {
81 if (is_a($oToken, '\Nominatim\Token\Word')) {
82 $ids[$oToken->getId()] = $oToken->getId();
91 * Add a new token for the given word.
93 * @param string $sWord Word the token describes.
94 * @param object $oToken Token object to add.
98 public function addToken($sWord, $oToken)
100 if (isset($this->aTokens[$sWord])) {
101 $this->aTokens[$sWord][] = $oToken;
103 $this->aTokens[$sWord] = array($oToken);
107 public function debugTokenByWordIdList()
109 $aWordsIDs = array();
110 foreach ($this->aTokens as $sToken => $aWords) {
111 foreach ($aWords as $aToken) {
112 $iId = $aToken->getId();
114 $aWordsIDs[$iId] = '#'.$sToken.'('.$aToken->debugCode().' '.$iId.')#';
122 public function debugInfo()
124 return $this->aTokens;