mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/16234] Fix & enhance Sphinx search backend functionality
PHPBB3-16234 PHPBB3-16233 PHPBB3-15367 PHPBB3-13958
This commit is contained in:
parent
4fb9c1cd98
commit
22417e3d9c
1 changed files with 10 additions and 10 deletions
|
@ -436,21 +436,21 @@ class fulltext_sphinx
|
||||||
public function split_keywords(&$keywords, $terms)
|
public function split_keywords(&$keywords, $terms)
|
||||||
{
|
{
|
||||||
// Keep quotes and new lines
|
// Keep quotes and new lines
|
||||||
$keywords = str_replace(array['"', "\n"], array['"', ' '], trim($keywords));
|
$keywords = str_replace(['"', "\n"], ['"', ' '], trim($keywords));
|
||||||
|
|
||||||
if ($terms == 'all')
|
if ($terms == 'all')
|
||||||
{
|
{
|
||||||
// Replaces verbal operators OR and NOT with special characters | and -, unless appearing within quotation marks
|
// Replaces verbal operators OR and NOT with special characters | and -, unless appearing within quotation marks
|
||||||
$match = array['#\sor\s(?=([^"]*"[^"]*")*[^"]*$)#i', '#\snot\s(?=([^"]*"[^"]*")*[^"]*$)#i'];
|
$match = ['#\sor\s(?=([^"]*"[^"]*")*[^"]*$)#i', '#\snot\s(?=([^"]*"[^"]*")*[^"]*$)#i'];
|
||||||
$replace = array[' | ', ' -'];
|
$replace = [' | ', ' -'];
|
||||||
|
|
||||||
$keywords = preg_replace($match, $replace, $keywords);
|
$keywords = preg_replace($match, $replace, $keywords);
|
||||||
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
|
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$match = array['\\', '(',')','|','!','@','~', '/', '^', '$', '=','&', '<', '>'];
|
$match = ['\\', '(',')','|','!','@','~', '/', '^', '$', '=','&', '<', '>'];
|
||||||
$replace = array[' ', ' ', ' ', ' ',' ',' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
|
$replace = [' ', ' ', ' ', ' ',' ',' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
|
||||||
|
|
||||||
$keywords = str_replace($match, $replace, $keywords);
|
$keywords = str_replace($match, $replace, $keywords);
|
||||||
$this->sphinx->SetMatchMode(SPH_MATCH_ANY);
|
$this->sphinx->SetMatchMode(SPH_MATCH_ANY);
|
||||||
|
@ -497,17 +497,17 @@ class fulltext_sphinx
|
||||||
*/
|
*/
|
||||||
public function sphinx_clean_search_string($search_string)
|
public function sphinx_clean_search_string($search_string)
|
||||||
{
|
{
|
||||||
$from = array['@', '^', '$', '!', '<', '>', '"', '&', '\''];
|
$from = ['@', '^', '$', '!', '<', '>', '"', '&', '\''];
|
||||||
$to = array['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
|
$to = ['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
|
||||||
|
|
||||||
$search_string = str_replace($from, $to, $search_string);
|
$search_string = str_replace($from, $to, $search_string);
|
||||||
|
|
||||||
$search_string = strrev($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);
|
$search_string = strrev($search_string);
|
||||||
|
|
||||||
$match = array['#(/|\\\\/)(?)#', '#(~|\\\\~)(?!\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)|=$)#'];
|
$match = ['#(/|\\\\/)(?)#', '#(~|\\\\~)(?!\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*)', '\<\<', '\='];
|
$replace = ['\/', '\~', '("$1 $2 $3 $4"|$1$2$3$4*)', '\<\<', '\='];
|
||||||
|
|
||||||
$search_string = preg_replace($match, $replace, $search_string);
|
$search_string = preg_replace($match, $replace, $search_string);
|
||||||
$search_string = preg_replace('#\s+"\|#', '"|', $search_string);
|
$search_string = preg_replace('#\s+"\|#', '"|', $search_string);
|
||||||
|
|
Loading…
Add table
Reference in a new issue