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 /// Number of terms in the word.
19 public function __construct($iId, $iSearchNameCount, $iTermCount, $iMatchScore = 1)
22 $this->iSearchNameCount = $iSearchNameCount;
23 $this->iTermCount = $iTermCount;
24 $this->iMatchScore = $iMatchScore;
27 public function getId()
33 * Check if the token can be added to the given search.
34 * Derive new searches by adding this token to an existing search.
36 * @param object $oSearch Partial search description derived so far.
37 * @param object $oPosition Description of the token position within
40 * @return True if the token is compatible with the search configuration
43 public function isExtendable($oSearch, $oPosition)
45 return !$oPosition->isPhrase('country');
49 * Derive new searches by adding this token to an existing search.
51 * @param object $oSearch Partial search description derived so far.
52 * @param object $oPosition Description of the token position within
55 * @return SearchDescription[] List of derived search descriptions.
57 public function extendSearch($oSearch, $oPosition)
59 // Full words can only be a name if they appear at the beginning
60 // of the phrase. In structured search the name must forcably in
61 // the first phrase. In unstructured search it may be in a later
62 // phrase when the first phrase is a house number.
63 if ($oSearch->hasName()
64 || !($oPosition->isFirstPhrase() || $oPosition->isPhrase(''))
66 if ($this->iTermCount > 1
67 && ($oPosition->isPhrase('') || !$oPosition->isFirstPhrase())
69 $oNewSearch = $oSearch->clone($this->iMatchScore);
70 $oNewSearch->addAddressToken($this->iId);
72 return array($oNewSearch);
74 } elseif (!$oSearch->hasName(true)) {
75 $oNewSearch = $oSearch->clone($this->iMatchScore);
76 $oNewSearch->addNameToken(
78 CONST_Search_NameOnlySearchFrequencyThreshold
79 && $this->iSearchNameCount
80 < CONST_Search_NameOnlySearchFrequencyThreshold
83 return array($oNewSearch);
89 public function debugInfo()
95 'count' => $this->iSearchNameCount,
96 'terms' => $this->iTermCount,
97 'score' => $this->iMatchScore
102 public function debugCode()