2018-05-15 00:04:15 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Nominatim\Token;
|
|
|
|
|
2020-12-15 12:09:55 +03:00
|
|
|
require_once(CONST_LibDir.'/SpecialSearchOperator.php');
|
2018-05-15 00:04:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A word token describing a place type.
|
|
|
|
*/
|
|
|
|
class SpecialTerm
|
|
|
|
{
|
2018-05-15 00:23:38 +03:00
|
|
|
/// Database word id, if applicable.
|
2018-05-15 00:04:15 +03:00
|
|
|
public $iId;
|
2018-05-15 00:23:38 +03:00
|
|
|
/// Class (or OSM tag key) of the place to look for.
|
2018-05-15 00:04:15 +03:00
|
|
|
public $sClass;
|
2018-05-15 00:23:38 +03:00
|
|
|
/// Type (or OSM tag value) of the place to look for.
|
2018-05-15 00:04:15 +03:00
|
|
|
public $sType;
|
2018-05-15 00:23:38 +03:00
|
|
|
/// Relationship of the operator to the object (see Operator class).
|
2018-05-15 00:04:15 +03:00
|
|
|
public $iOperator;
|
|
|
|
|
|
|
|
public function __construct($iID, $sClass, $sType, $iOperator)
|
|
|
|
{
|
|
|
|
$this->iId = $iID;
|
|
|
|
$this->sClass = $sClass;
|
|
|
|
$this->sType = $sType;
|
|
|
|
$this->iOperator = $iOperator;
|
|
|
|
}
|
|
|
|
|
2021-07-17 21:24:33 +03:00
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->iId;
|
|
|
|
}
|
|
|
|
|
2021-07-17 23:01:35 +03:00
|
|
|
/**
|
|
|
|
* Check if the token can be added to the given search.
|
|
|
|
* Derive new searches by adding this token to an existing search.
|
|
|
|
*
|
|
|
|
* @param object $oSearch Partial search description derived so far.
|
|
|
|
* @param object $oPosition Description of the token position within
|
|
|
|
the query.
|
|
|
|
*
|
|
|
|
* @return True if the token is compatible with the search configuration
|
|
|
|
* given the position.
|
|
|
|
*/
|
|
|
|
public function isExtendable($oSearch, $oPosition)
|
|
|
|
{
|
|
|
|
return !$oSearch->hasOperator() && $oPosition->isPhrase('');
|
|
|
|
}
|
|
|
|
|
2021-07-17 21:24:33 +03:00
|
|
|
/**
|
|
|
|
* Derive new searches by adding this token to an existing search.
|
|
|
|
*
|
|
|
|
* @param object $oSearch Partial search description derived so far.
|
|
|
|
* @param object $oPosition Description of the token position within
|
|
|
|
the query.
|
|
|
|
*
|
|
|
|
* @return SearchDescription[] List of derived search descriptions.
|
|
|
|
*/
|
|
|
|
public function extendSearch($oSearch, $oPosition)
|
|
|
|
{
|
|
|
|
$iSearchCost = 2;
|
|
|
|
|
|
|
|
$iOp = $this->iOperator;
|
|
|
|
if ($iOp == \Nominatim\Operator::NONE) {
|
|
|
|
if ($oSearch->hasName() || $oSearch->getContext()->isBoundedSearch()) {
|
|
|
|
$iOp = \Nominatim\Operator::NAME;
|
|
|
|
} else {
|
|
|
|
$iOp = \Nominatim\Operator::NEAR;
|
|
|
|
}
|
|
|
|
$iSearchCost += 2;
|
|
|
|
} elseif (!$oPosition->isFirstToken() && !$oPosition->isLastToken()) {
|
|
|
|
$iSearchCost += 2;
|
|
|
|
}
|
|
|
|
if ($oSearch->hasHousenumber()) {
|
|
|
|
$iSearchCost ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$oNewSearch = $oSearch->clone($iSearchCost);
|
|
|
|
$oNewSearch->setPoiSearch($iOp, $this->sClass, $this->sType);
|
|
|
|
|
|
|
|
return array($oNewSearch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-15 00:04:15 +03:00
|
|
|
public function debugInfo()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'ID' => $this->iId,
|
|
|
|
'Type' => 'special term',
|
|
|
|
'Info' => array(
|
|
|
|
'class' => $this->sClass,
|
|
|
|
'type' => $this->sType,
|
2018-07-17 23:23:27 +03:00
|
|
|
'operator' => \Nominatim\Operator::toString($this->iOperator)
|
2018-05-15 00:04:15 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2021-07-17 21:24:33 +03:00
|
|
|
|
|
|
|
public function debugCode()
|
|
|
|
{
|
|
|
|
return 'S';
|
|
|
|
}
|
2018-05-15 00:04:15 +03:00
|
|
|
}
|