mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-27 00:49:55 +03:00
ec3f6c9c42
Moves token and phrase position and phrase type into a separate class that is handed in when assembling the search description. This drastically reduces the number of parameters for the function to extend the search descriptions and gives us more flexibility in the future for more complex positional analysis.
88 lines
1.9 KiB
PHP
88 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Nominatim;
|
|
|
|
/**
|
|
* Description of the position of a token within a query.
|
|
*/
|
|
class SearchPosition
|
|
{
|
|
private $sPhraseType;
|
|
|
|
private $iPhrase;
|
|
private $iNumPhrases;
|
|
|
|
private $iToken;
|
|
private $iNumTokens;
|
|
|
|
|
|
public function __construct($sPhraseType, $iPhrase, $iNumPhrases)
|
|
{
|
|
$this->sPhraseType = $sPhraseType;
|
|
$this->iPhrase = $iPhrase;
|
|
$this->iNumPhrases = $iNumPhrases;
|
|
}
|
|
|
|
public function setTokenPosition($iToken, $iNumTokens)
|
|
{
|
|
$this->iToken = $iToken;
|
|
$this->iNumTokens = $iNumTokens;
|
|
}
|
|
|
|
/**
|
|
* Check if the phrase can be of the given type.
|
|
*
|
|
* @param string $sType Type of phrse requested.
|
|
*
|
|
* @return True if the phrase is untyped or of the given type.
|
|
*/
|
|
public function maybePhrase($sType)
|
|
{
|
|
return $this->sPhraseType == '' || $this->sPhraseType == $sType;
|
|
}
|
|
|
|
/**
|
|
* Check if the phrase is exactly of the given type.
|
|
*
|
|
* @param string $sType Type of phrse requested.
|
|
*
|
|
* @return True if the phrase of the given type.
|
|
*/
|
|
public function isPhrase($sType)
|
|
{
|
|
return $this->sPhraseType == $sType;
|
|
}
|
|
|
|
/**
|
|
* Return true if the token is the very first in the query.
|
|
*/
|
|
public function isFirstToken()
|
|
{
|
|
return $this->iPhrase == 0 && $this->iToken == 0;
|
|
}
|
|
|
|
/**
|
|
* Check if the token is the final one in the query.
|
|
*/
|
|
public function isLastToken()
|
|
{
|
|
return $this->iToken + 1 == $this->iNumTokens && $this->iPhrase + 1 == $this->iNumPhrases;
|
|
}
|
|
|
|
/**
|
|
* Check if the current token is part of the first phrase in the query.
|
|
*/
|
|
public function isFirstPhrase()
|
|
{
|
|
return $this->iPhrase == 0;
|
|
}
|
|
|
|
/**
|
|
* Get the phrase position in the query.
|
|
*/
|
|
public function getPhrase()
|
|
{
|
|
return $this->iPhrase;
|
|
}
|
|
}
|