1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 00:02:18 +02:00

[ticket/16234] Fix & enhance Sphinx search backend functionality

PHPBB3-16234
PHPBB3-16233
PHPBB3-15367
PHPBB3-13958
This commit is contained in:
KYPREO 2020-01-04 04:15:10 +11:00
parent 4fb9c1cd98
commit 22417e3d9c

View File

@ -436,21 +436,21 @@ class fulltext_sphinx
public function split_keywords(&$keywords, $terms)
{
// Keep quotes and new lines
$keywords = str_replace(array['"', "\n"], array['"', ' '], trim($keywords));
$keywords = str_replace(['"', "\n"], ['"', ' '], trim($keywords));
if ($terms == 'all')
{
// Replaces verbal operators OR and NOT with special characters | and -, unless appearing within quotation marks
$match = array['#\sor\s(?=([^"]*"[^"]*")*[^"]*$)#i', '#\snot\s(?=([^"]*"[^"]*")*[^"]*$)#i'];
$replace = array[' | ', ' -'];
$match = ['#\sor\s(?=([^"]*"[^"]*")*[^"]*$)#i', '#\snot\s(?=([^"]*"[^"]*")*[^"]*$)#i'];
$replace = [' | ', ' -'];
$keywords = preg_replace($match, $replace, $keywords);
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
}
else
{
$match = array['\\', '(',')','|','!','@','~', '/', '^', '$', '=','&', '<', '>'];
$replace = array[' ', ' ', ' ', ' ',' ',' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
$match = ['\\', '(',')','|','!','@','~', '/', '^', '$', '=','&', '<', '>'];
$replace = [' ', ' ', ' ', ' ',' ',' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
$keywords = str_replace($match, $replace, $keywords);
$this->sphinx->SetMatchMode(SPH_MATCH_ANY);
@ -497,17 +497,17 @@ class fulltext_sphinx
*/
public function sphinx_clean_search_string($search_string)
{
$from = array['@', '^', '$', '!', '<', '>', '"', '&', '\''];
$to = array['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
$from = ['@', '^', '$', '!', '&lt;', '&gt;', '&quot;', '&amp;', '\''];
$to = ['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
$search_string = str_replace($from, $to, $search_string);
$search_string = strrev($search_string);
$search_string = preg_replace(array['#\/(?!"[^"]+")#', '#~(?!"[^"]+")#'], array['/\\', '~\\'], $search_string);
$search_string = preg_replace(['#\/(?!"[^"]+")#', '#~(?!"[^"]+")#'], ['/\\', '~\\'], $search_string);
$search_string = strrev($search_string);
$match = array['#(/|\\\\/)(?![1-9](\s|$))#', '#(~|\\\\~)(?!\d{1,2}(\s|$))#', '#((?:\p{L}|\p{N})+)-((?:\p{L}|\p{N})+)(?:-((?:\p{L}|\p{N})+))?(?:-((?:\p{L}|\p{N})+))?#i', '#<<\s*$#', '#(\S\K=|=(?=\s)|=$)#'];
$replace = array['\/', '\~', '("$1 $2 $3 $4"|$1$2$3$4*)', '\<\<', '\='];
$match = ['#(/|\\\\/)(?![1-9](\s|$))#', '#(~|\\\\~)(?!\d{1,2}(\s|$))#', '#((?:\p{L}|\p{N})+)-((?:\p{L}|\p{N})+)(?:-((?:\p{L}|\p{N})+))?(?:-((?:\p{L}|\p{N})+))?#i', '#<<\s*$#', '#(\S\K=|=(?=\s)|=$)#'];
$replace = ['\/', '\~', '("$1 $2 $3 $4"|$1$2$3$4*)', '\<\<', '\='];
$search_string = preg_replace($match, $replace, $search_string);
$search_string = preg_replace('#\s+"\|#', '"|', $search_string);