3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 namespace Nominatim\Token;
13 require_once(CONST_LibDir.'/SpecialSearchOperator.php');
16 * A word token describing a place type.
20 /// Database word id, if applicable.
22 /// Class (or OSM tag key) of the place to look for.
24 /// Type (or OSM tag value) of the place to look for.
26 /// Relationship of the operator to the object (see Operator class).
29 public function __construct($iID, $sClass, $sType, $iOperator)
32 $this->sClass = $sClass;
33 $this->sType = $sType;
34 $this->iOperator = $iOperator;
37 public function getId()
43 * Check if the token can be added to the given search.
44 * Derive new searches by adding this token to an existing search.
46 * @param object $oSearch Partial search description derived so far.
47 * @param object $oPosition Description of the token position within
50 * @return True if the token is compatible with the search configuration
53 public function isExtendable($oSearch, $oPosition)
55 return !$oSearch->hasOperator()
56 && $oPosition->isPhrase('')
57 && ($this->iOperator != \Nominatim\Operator::NONE
58 || (!$oSearch->hasAddress() && !$oSearch->hasHousenumber() && !$oSearch->hasCountry()));
62 * Derive new searches by adding this token to an existing search.
64 * @param object $oSearch Partial search description derived so far.
65 * @param object $oPosition Description of the token position within
68 * @return SearchDescription[] List of derived search descriptions.
70 public function extendSearch($oSearch, $oPosition)
74 $iOp = $this->iOperator;
75 if ($iOp == \Nominatim\Operator::NONE) {
76 if ($oPosition->isFirstToken()
77 || $oSearch->hasName()
78 || $oSearch->getContext()->isBoundedSearch()
80 $iOp = \Nominatim\Operator::NAME;
83 $iOp = \Nominatim\Operator::NEAR;
85 if (!$oPosition->isFirstToken()) {
89 } elseif ($oPosition->isFirstToken()) {
91 } elseif ($oPosition->isLastToken()) {
97 if ($oSearch->hasHousenumber()) {
101 $oNewSearch = $oSearch->clone($iSearchCost);
102 $oNewSearch->setPoiSearch($iOp, $this->sClass, $this->sType);
104 return array($oNewSearch);
108 public function debugInfo()
112 'Type' => 'special term',
114 'class' => $this->sClass,
115 'type' => $this->sType,
116 'operator' => \Nominatim\Operator::toString($this->iOperator)
121 public function debugCode()