From 2161a7b8468420433be5410771aeb40aaec88081 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 27 Feb 2026 12:02:16 +0100 Subject: [PATCH] Search/Fixup * dashes also split words into multiple tokens, so they are now stripped from search entirely (see: 'weather-beaten') * only search for the full search input if the tokenizer didn't yield any fulltext tokens. This should fix search performance after 00f048d3ae82fbea62510b7a23a473de656db8d7 * fixes #497 --- includes/components/filter.class.php | 8 ++------ includes/components/search.class.php | 13 ++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/includes/components/filter.class.php b/includes/components/filter.class.php index 6cdc439b..810e1a49 100644 --- a/includes/components/filter.class.php +++ b/includes/components/filter.class.php @@ -65,7 +65,7 @@ abstract class Filter protected const PATTERN_CRV = '/[\p{C};:%\\\\]/ui'; protected const PATTERN_INT = '/\D/'; public const PATTERN_PARAM = '/^[\p{L}\p{Sm} \d\p{P}]+$/ui'; - public const PATTERN_FT = '/[^[:alpha:] \d_-]/iu'; // +-*<>@()~" have special meaning; ' seems to fuck up the search; other irregular cases? + public const PATTERN_FT = '/[^[:alpha:] \d_]/iu'; // +-*<>@()~" have special meaning; ' seems to fuck up the search; other irregular cases? protected const ENUM_FACTION = array( 469, 1037, 1106, 529, 1012, 87, 21, 910, 609, 942, 909, 530, 69, 577, 930, 1068, 1104, 729, 369, 92, 54, 946, 67, 1052, 749, 47, 989, 1090, 1098, 978, 1011, 93, 1015, 1038, 76, 470, 349, 1031, 1077, 809, @@ -629,11 +629,7 @@ abstract class Filter // note: a fulltext search purely from exclude tokens will return no result foreach ($fulltext as $ft) - { - // cant have trailing/leading dashes. FT confuses them for additional modifiers and dies with a syntax error - // would be an issue for all modifiers, but Filter::PATTERN_FT only allows for - at this point - $this->ftTokens[$field][] = ($ex ? '-' : '+') . preg_replace('/^-+|-+$/', '', $ft) . '*'; - } + $this->ftTokens[$field][] = ($ex ? '-' : '+') . $ft . '*'; } } diff --git a/includes/components/search.class.php b/includes/components/search.class.php index 029b864e..e8e35dda 100644 --- a/includes/components/search.class.php +++ b/includes/components/search.class.php @@ -118,11 +118,7 @@ class Search // note: a fulltext search purely from exclude tokens will return no result foreach ($fulltext as $ft) - { - // cant have trailing/leading dashes. FT confuses them for additional modifiers and dies with a syntax error - // would be an issue for all modifiers, but Filter::PATTERN_FT only allows for - at this point - $this->fulltext[] = ($ex ? '-' : '+') . preg_replace('/^-+|-+$/', '', $ft) . '*'; - } + $this->fulltext[] = ($ex ? '-' : '+') . $ft . '*'; } else $this->invalid[] = $raw; @@ -181,10 +177,9 @@ class Search $qry = []; if ($this->fulltext) $qry = array_map(fn($x) => [$x, $this->fulltext, 'MATCH'], $fields); - - $strBak = trim($this->query); - if (mb_strlen($strBak) > 2 || Lang::getLocale()->isLogographic()) - $qry = array_merge($qry, array_map(fn($x) => [$x, $strBak], $fields)); + else if ($strBak = trim($this->query)) + if (mb_strlen($strBak) > 2 || Lang::getLocale()->isLogographic()) + $qry = array_map(fn($x) => [$x, $strBak], $fields); // single cnd? if (count($qry) > 1)