From 48e0482dbde63110d5140c080293a848e681de51 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 1 Aug 2023 17:20:42 +0300 Subject: [PATCH] update Filter::searchQuery method --- library/filter.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/library/filter.php b/library/filter.php index 958098e..0f277b5 100644 --- a/library/filter.php +++ b/library/filter.php @@ -91,8 +91,18 @@ class Filter { $query = trim($query); - // Quote reserved keyword operators + // Return short or empty queries + if (mb_strlen($query) <= 1) { + + return false; + } + + // Lowercase query to deactivate reserved operators + $query = mb_strtolower($query); + + // Quote other operators $operators = [ + /* lowercased 'MAYBE', 'AND', 'OR', @@ -102,8 +112,8 @@ class Filter { 'ZONE', 'ZONESPAN', 'PARAGRAPH', - - '\\', '/', '~', '@', '!', '"', '(', ')', '[', ']', '|', '?', '%', '-', '>', '<', ':', ';', '^', '$' + */ + '\\', '/', '~', '@', '!', '"', "'", '(', ')', '[', ']', '|', '?', '%', '-', '>', '<', ':', ';', '^', '$' ]; foreach ($operators as $operator) { @@ -131,13 +141,13 @@ class Filter { if (mb_strlen($word) > 1) { - $words[] = sprintf('%s*', $word); + $words[] = sprintf('(%s*)', $word); } } - $query = sprintf('@title %s | "%s" | %s', $query, - $crc32query, - implode(' | ', $words)); + $query = sprintf('@title %s | "%s" | (%s)', $query, + $crc32query, + implode(' | ', $words)); } }