1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/16941] Add sphinx tests to 3.3.x

Also adjust Sphinx keywords splitting to be consistent with other search
backends when it comes to handling hyphen (like ignoring hyphen when it hasn't
NOT meaning and ignoring hyphen wrapped with "plus" signs)

PHPBB3-16941
This commit is contained in:
rxu
2021-12-12 10:53:56 +07:00
parent 4140d50f6a
commit 80a08d9c54
7 changed files with 263 additions and 6 deletions

View File

@@ -455,9 +455,47 @@ class fulltext_sphinx
$this->sphinx->SetMatchMode(SPH_MATCH_ANY);
}
if (strlen($keywords) > 0)
// Split words
$split_keywords = preg_replace('#([^\p{L}\p{N}\'*"()])#u', '$1$1', str_replace('\'\'', '\' \'', trim($keywords)));
$matches = array();
preg_match_all('#(?:[^\p{L}\p{N}*"()]|^)([+\-|]?(?:[\p{L}\p{N}*"()]+\'?)*[\p{L}\p{N}*"()])(?:[^\p{L}\p{N}*"()]|$)#u', $split_keywords, $matches);
$this->split_words = $matches[1];
if ($terms == 'any')
{
$this->search_query = str_replace('"', '"', $keywords);
$this->search_query = '';
foreach ($this->split_words as $word)
{
if ((strpos($word, '+') === 0) || (strpos($word, '-') === 0) || (strpos($word, '|') === 0))
{
$word = substr($word, 1);
}
$this->search_query .= $word . ' ';
}
}
else
{
$this->search_query = '';
foreach ($this->split_words as $word)
{
if ((strpos($word, '+') === 0) || (strpos($word, '-') === 0))
{
$this->search_query .= $word . ' ';
}
else if (strpos($word, '|') === 0)
{
$this->search_query .= substr($word, 1) . ' ';
}
else
{
$this->search_query .= '+' . $word . ' ';
}
}
}
if ($this->search_query)
{
$this->search_query = str_replace('"', '"', $this->search_query);
return true;
}