The token string is only required by the PartialToken type, so
it can simply save the token string internally. No need to pass
it to every type.
Also moves the check for multi-word partials to the token loader
code in the tokenizer. Multi-word partials can only happen with
the legacy tokenizer and when the database was loaded with an
older version of Nominatim. No need to keep the check for
everybody.
foreach ($aWordsetSearches as $oCurrentSearch) {
foreach ($oValidTokens->get($sToken) as $oSearchTerm) {
$aNewSearches = $oCurrentSearch->extendWithSearchTerm(
foreach ($aWordsetSearches as $oCurrentSearch) {
foreach ($oValidTokens->get($sToken) as $oSearchTerm) {
$aNewSearches = $oCurrentSearch->extendWithSearchTerm(
$oSearchTerm,
$oPosition
);
$oSearchTerm,
$oPosition
);
/**
* Derive new searches by adding a full term to the existing search.
*
/**
* Derive new searches by adding a full term to the existing search.
*
- * @param string $sToken Term for the token.
* @param object $oSearchTerm Description of the token.
* @param object $oPosition Description of the token position within
the query.
*
* @return SearchDescription[] List of derived search descriptions.
*/
* @param object $oSearchTerm Description of the token.
* @param object $oPosition Description of the token position within
the query.
*
* @return SearchDescription[] List of derived search descriptions.
*/
- public function extendWithSearchTerm($sToken, $oSearchTerm, $oPosition)
+ public function extendWithSearchTerm($oSearchTerm, $oPosition)
{
$aNewSearches = array();
{
$aNewSearches = array();
}
} elseif (!$oPosition->isPhrase('country')
&& is_a($oSearchTerm, '\Nominatim\Token\Partial')
}
} elseif (!$oPosition->isPhrase('country')
&& is_a($oSearchTerm, '\Nominatim\Token\Partial')
- && strpos($sToken, ' ') === false
) {
$aNewSearches = $this->extendWithPartialTerm(
) {
$aNewSearches = $this->extendWithPartialTerm(
$oSearchTerm,
$oPosition
);
$oSearchTerm,
$oPosition
);
/**
* Derive new searches by adding a partial term to the existing search.
*
/**
* Derive new searches by adding a partial term to the existing search.
*
- * @param string $sToken Term for the token.
* @param object $oSearchTerm Description of the token.
* @param object $oPosition Description of the token position within
the query.
*
* @return SearchDescription[] List of derived search descriptions.
*/
* @param object $oSearchTerm Description of the token.
* @param object $oPosition Description of the token position within
the query.
*
* @return SearchDescription[] List of derived search descriptions.
*/
- private function extendWithPartialTerm($sToken, $oSearchTerm, $oPosition)
+ private function extendWithPartialTerm($oSearchTerm, $oPosition)
{
$aNewSearches = array();
$iWordID = $oSearchTerm->iId;
{
$aNewSearches = array();
$iWordID = $oSearchTerm->iId;
) {
$oSearch = clone $this;
$oSearch->iSearchRank++;
) {
$oSearch = clone $this;
$oSearch->iSearchRank++;
- if (preg_match('#^[0-9 ]+$#', $sToken)) {
+ if (preg_match('#^[0-9 ]+$#', $oSearchTerm->sToken)) {
$oSearch->iSearchRank++;
}
if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) {
$oSearch->iSearchRank++;
}
if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) {
if (empty($this->aName) && empty($this->aNameNonSearch)) {
$oSearch->iSearchRank++;
}
if (empty($this->aName) && empty($this->aNameNonSearch)) {
$oSearch->iSearchRank++;
}
- if (preg_match('#^[0-9 ]+$#', $sToken)) {
+ if (preg_match('#^[0-9 ]+$#', $oSearchTerm->sToken)) {
$oSearch->iSearchRank++;
}
if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) {
$oSearch->iSearchRank++;
}
if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) {
public $iId;
/// Number of appearances in the database.
public $iSearchNameCount;
public $iId;
/// Number of appearances in the database.
public $iSearchNameCount;
+ /// Normalised version of the partial word.
+ public $sToken;
- public function __construct($iId, $iSearchNameCount)
+ public function __construct($iId, $sToken, $iSearchNameCount)
+ $this->sToken = $sToken;
$this->iSearchNameCount = $iSearchNameCount;
}
$this->iSearchNameCount = $iSearchNameCount;
}
} else {
$oToken = new Token\Partial(
$iId,
} else {
$oToken = new Token\Partial(
$iId,
(int) $aWord['count']
);
}
(int) $aWord['count']
);
}
(int) $aWord['count'],
substr_count($aWord['word_token'], ' ')
);
(int) $aWord['count'],
substr_count($aWord['word_token'], ' ')
);
+ // For backward compatibility: ignore all partial tokens with more
+ // than one word.
+ } elseif (strpos($aWord['word_token'], ' ') === false) {
$oToken = new Token\Partial(
$iId,
$oToken = new Token\Partial(
$iId,
(int) $aWord['count']
);
}
(int) $aWord['count']
);
}