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 ($oSearch->hasName() || $oSearch->getContext()->isBoundedSearch()) {
77 $iOp = \Nominatim\Operator::NAME;
79 $iOp = \Nominatim\Operator::NEAR;
82 } elseif (!$oPosition->isFirstToken() && !$oPosition->isLastToken()) {
85 if ($oSearch->hasHousenumber()) {
89 $oNewSearch = $oSearch->clone($iSearchCost);
90 $oNewSearch->setPoiSearch($iOp, $this->sClass, $this->sType);
92 return array($oNewSearch);
96 public function debugInfo()
100 'Type' => 'special term',
102 'class' => $this->sClass,
103 'type' => $this->sType,
104 'operator' => \Nominatim\Operator::toString($this->iOperator)
109 public function debugCode()