3 namespace Nominatim\Token;
5 require_once(CONST_LibDir.'/SpecialSearchOperator.php');
8 * A word token describing a place type.
12 /// Database word id, if applicable.
14 /// Class (or OSM tag key) of the place to look for.
16 /// Type (or OSM tag value) of the place to look for.
18 /// Relationship of the operator to the object (see Operator class).
21 public function __construct($iID, $sClass, $sType, $iOperator)
24 $this->sClass = $sClass;
25 $this->sType = $sType;
26 $this->iOperator = $iOperator;
29 public function getId()
35 * Check if the token can be added to the given search.
36 * Derive new searches by adding this token to an existing search.
38 * @param object $oSearch Partial search description derived so far.
39 * @param object $oPosition Description of the token position within
42 * @return True if the token is compatible with the search configuration
45 public function isExtendable($oSearch, $oPosition)
47 return !$oSearch->hasOperator()
48 && $oPosition->isPhrase('')
49 && ($this->iOperator != \Nominatim\Operator::NONE
50 || (!$oSearch->hasAddress() && !$oSearch->hasHousenumber() && !$oSearch->hasCountry()));
54 * Derive new searches by adding this token to an existing search.
56 * @param object $oSearch Partial search description derived so far.
57 * @param object $oPosition Description of the token position within
60 * @return SearchDescription[] List of derived search descriptions.
62 public function extendSearch($oSearch, $oPosition)
66 $iOp = $this->iOperator;
67 if ($iOp == \Nominatim\Operator::NONE) {
68 if ($oSearch->hasName() || $oSearch->getContext()->isBoundedSearch()) {
69 $iOp = \Nominatim\Operator::NAME;
71 $iOp = \Nominatim\Operator::NEAR;
74 } elseif (!$oPosition->isFirstToken() && !$oPosition->isLastToken()) {
77 if ($oSearch->hasHousenumber()) {
81 $oNewSearch = $oSearch->clone($iSearchCost);
82 $oNewSearch->setPoiSearch($iOp, $this->sClass, $this->sType);
84 return array($oNewSearch);
88 public function debugInfo()
92 'Type' => 'special term',
94 'class' => $this->sClass,
95 'type' => $this->sType,
96 'operator' => \Nominatim\Operator::toString($this->iOperator)
101 public function debugCode()