X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/1d8e2961f0527a548989c1e38bb062f2f9e5877e..3cdfe066336ad19772d300a85d6c1feaadc074ea:/lib/TokenList.php?ds=sidebyside diff --git a/lib/TokenList.php b/lib/TokenList.php index 96b756f8..a419da6a 100644 --- a/lib/TokenList.php +++ b/lib/TokenList.php @@ -2,12 +2,12 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/TokenCountry.php'); -require_once(CONST_BasePath.'/lib/TokenHousenumber.php'); -require_once(CONST_BasePath.'/lib/TokenPostcode.php'); -require_once(CONST_BasePath.'/lib/TokenSpecialTerm.php'); -require_once(CONST_BasePath.'/lib/TokenWord.php'); -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/TokenCountry.php'); +require_once(CONST_LibDir.'/TokenHousenumber.php'); +require_once(CONST_LibDir.'/TokenPostcode.php'); +require_once(CONST_LibDir.'/TokenSpecialTerm.php'); +require_once(CONST_LibDir.'/TokenWord.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); /** * Saves information about the tokens that appear in a search query. @@ -32,6 +32,17 @@ class TokenList // List of list of tokens indexed by their word_token. private $aTokens = array(); + + /** + * Return total number of tokens. + * + * @return Integer + */ + public function count() + { + return count($this->aTokens); + } + /** * Check if there are tokens for the given token word. * @@ -44,6 +55,18 @@ class TokenList return isset($this->aTokens[$sWord]); } + /** + * Check if there are partial or full tokens for the given word. + * + * @param string $sWord Token word to look for. + * + * @return bool True if there is one or more token for the token word. + */ + public function containsAny($sWord) + { + return isset($this->aTokens[$sWord]) || isset($this->aTokens[' '.$sWord]); + } + /** * Get the list of tokens for the given token word. * @@ -57,10 +80,25 @@ class TokenList return isset($this->aTokens[$sWord]) ? $this->aTokens[$sWord] : array(); } + public function getFullWordIDs() + { + $ids = array(); + + foreach ($this->aTokens as $aTokenList) { + foreach ($aTokenList as $oToken) { + if (is_a($oToken, '\Nominatim\Token\Word') && !$oToken->bPartial) { + $ids[$oToken->iId] = $oToken->iId; + } + } + } + + return $ids; + } + /** * Add token information from the word table in the database. * - * @param object $oDB Database connection. + * @param object $oDB Nominatim::DB instance. * @param string[] $aTokens List of tokens to look up in the database. * @param string[] $aCountryCodes List of country restrictions. * @param string $sNormQuery Normalized query string. @@ -74,11 +112,11 @@ class TokenList $sSQL = 'SELECT word_id, word_token, word, class, type, country_code,'; $sSQL .= ' operator, coalesce(search_name_count, 0) as count'; $sSQL .= ' FROM word WHERE word_token in ('; - $sSQL .= join(',', array_map('getDBQuoted', $aTokens)).')'; + $sSQL .= join(',', $oDB->getDBQuotedList($aTokens)).')'; Debug::printSQL($sSQL); - $aDBWords = chksql($oDB->getAll($sSQL), 'Could not get word tokens.'); + $aDBWords = $oDB->getAll($sSQL, null, 'Could not get word tokens.'); foreach ($aDBWords as $aWord) { $oToken = null; @@ -114,7 +152,7 @@ class TokenList $iId, $aWord['class'], $aWord['type'], - $aWord['operator'] ? Operator::NONE : Operator::NEAR + $aWord['operator'] ? Operator::NEAR : Operator::NONE ); } } elseif ($aWord['country_code']) { @@ -127,8 +165,9 @@ class TokenList } else { $oToken = new Token\Word( $iId, - $aWord['word'][0] != ' ', - (int) $aWord['count'] + $aWord['word_token'][0] != ' ', + (int) $aWord['count'], + substr_count($aWord['word_token'], ' ') ); }