Drop tokens for special and postcode searches already when
collecting them for ValidTokens when they cannot be found
in the normalized query.
return $aSearchResults;
}
return $aSearchResults;
}
- public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured, $sNormQuery)
+ public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured)
{
/*
Calculate all searches using aValidTokens i.e.
{
/*
Calculate all searches using aValidTokens i.e.
// If the token is valid
if (isset($aValidTokens[' '.$sToken])) {
foreach ($aValidTokens[' '.$sToken] as $aSearchTerm) {
// If the token is valid
if (isset($aValidTokens[' '.$sToken])) {
foreach ($aValidTokens[' '.$sToken] as $aSearchTerm) {
- // Recheck if the original word shows up in the query.
- $bWordInQuery = false;
- if (isset($aSearchTerm['word']) && $aSearchTerm['word']) {
- $bWordInQuery = strpos(
- $sNormQuery,
- $this->normTerm($aSearchTerm['word'])
- ) !== false;
- }
$aNewSearches = $oCurrentSearch->extendWithFullTerm(
$aSearchTerm,
$aNewSearches = $oCurrentSearch->extendWithFullTerm(
$aSearchTerm,
isset($aValidTokens[$sToken])
&& strpos($sToken, ' ') === false,
$sPhraseType,
isset($aValidTokens[$sToken])
&& strpos($sToken, ' ') === false,
$sPhraseType,
+ // Special terms need to appear in their normalized form.
+ if ($aToken['word'] && $aToken['class']) {
+ $sNormWord = $this->normTerm($aToken['word']);
+ if (strpos($sNormQuery, $sNormWord) === false) {
+ continue;
+ }
+ }
+
if (isset($aValidTokens[$aToken['word_token']])) {
$aValidTokens[$aToken['word_token']][] = $aToken;
} else {
if (isset($aValidTokens[$aToken['word_token']])) {
$aValidTokens[$aToken['word_token']][] = $aToken;
} else {
// Any words that have failed completely?
// TODO: suggestions
// Any words that have failed completely?
// TODO: suggestions
- $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases, $sNormQuery);
+ $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases);
if ($this->bReverseInPlan) {
// Reverse phrase array and also reverse the order of the wordsets in
if ($this->bReverseInPlan) {
// Reverse phrase array and also reverse the order of the wordsets in
if (sizeof($aPhrases) > 1) {
$aPhrases[sizeof($aPhrases)-1]->invertWordSets();
}
if (sizeof($aPhrases) > 1) {
$aPhrases[sizeof($aPhrases)-1]->invertWordSets();
}
- $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false, $sNormQuery);
+ $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false);
foreach ($aGroupedSearches as $aSearches) {
foreach ($aSearches as $aSearch) {
foreach ($aGroupedSearches as $aSearches) {
foreach ($aSearches as $aSearch) {
* Derive new searches by adding a full term to the existing search.
*
* @param mixed[] $aSearchTerm Description of the token.
* Derive new searches by adding a full term to the existing search.
*
* @param mixed[] $aSearchTerm Description of the token.
- * @param bool $bWordInQuery True, if the normalised version of the word
- * is contained in the query.
* @param bool $bHasPartial True if there are also tokens of partial terms
* with the same name.
* @param string $sPhraseType Type of phrase the token is contained in.
* @param bool $bHasPartial True if there are also tokens of partial terms
* with the same name.
* @param string $sPhraseType Type of phrase the token is contained in.
*
* @return SearchDescription[] List of derived search descriptions.
*/
*
* @return SearchDescription[] List of derived search descriptions.
*/
- public function extendWithFullTerm($aSearchTerm, $bWordInQuery, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken, &$iGlobalRank)
+ public function extendWithFullTerm($aSearchTerm, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken, &$iGlobalRank)
{
$aNewSearches = array();
{
$aNewSearches = array();
// We need to try the case where the postal code is the primary element
// (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode)
// so try both.
// We need to try the case where the postal code is the primary element
// (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode)
// so try both.
- if (!$this->sPostcode && $bWordInQuery
+ if (!$this->sPostcode
+ && $aSearchTerm['word']
&& pg_escape_string($aSearchTerm['word']) == $aSearchTerm['word']
) {
// If we have structured search or this is the first term,
&& pg_escape_string($aSearchTerm['word']) == $aSearchTerm['word']
) {
// If we have structured search or this is the first term,
}
$aNewSearches[] = $oSearch;
}
}
$aNewSearches[] = $oSearch;
}
- } elseif ($sPhraseType == ''
- && $aSearchTerm['class'] !== '' && $aSearchTerm['class'] !== null
- ) {
- // require a normalized exact match of the term
- // if we have the normalizer version of the query
- // available
- if ($this->iOperator == Operator::NONE
- && (isset($aSearchTerm['word']) && $aSearchTerm['word'])
- && $bWordInQuery
- ) {
+ } elseif ($sPhraseType == '' && $aSearchTerm['class']) {
+ if ($this->iOperator == Operator::NONE) {
$oSearch = clone $this;
$oSearch->iSearchRank++;
$oSearch = clone $this;
$oSearch->iSearchRank++;