From f491fa0cf897bbe76aaa99e415bfe00d1cbf199d Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 23:19:57 +0200 Subject: [PATCH 1/3] UserSearchQueries.php: fix query generation --- inc/Data/UserPostQueries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Data/UserPostQueries.php b/inc/Data/UserPostQueries.php index 0b51330a..52671dc5 100644 --- a/inc/Data/UserPostQueries.php +++ b/inc/Data/UserPostQueries.php @@ -220,7 +220,7 @@ class UserPostQueries { for ($i = 0; $i < \count($flags); $i++) { // Yes, vichan stores the flag inside the generated HTML. Now you know why it's slow as shit. // English lacks the words to express my feelings about it in a satisfying manner. - $flag_acc[] = "CONCAT('%', :flag$i, '%')"; + $flag_acc[] = "CONCAT('%', :flag$i, '%')"; } $where_acc[] = 'body_nomarkup LIKE (' . \implode(' OR ', $flag_acc) . ')'; } From 67d9a638db5f1a0a0bc7fcf9b49e759c31604031 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 22:23:49 +0200 Subject: [PATCH 2/3] SearchService.php: fix flag filtering --- inc/Service/SearchService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/Service/SearchService.php b/inc/Service/SearchService.php index 8a1b3742..1bfcf0f9 100644 --- a/inc/Service/SearchService.php +++ b/inc/Service/SearchService.php @@ -383,7 +383,9 @@ class SearchService { $flags = []; if (!empty($filters->flag) && !empty($this->flag_map)) { - $flags = $this->matchStrings($this->flag_map, $filters->flag); + // A double array_values is necessary in order to re-index the array, otherwise it's left with random indexes. + $reverse_flags = \array_values(\array_values($this->flag_map)); + $flags = $this->matchStrings($reverse_flags, $filters->flag); if (empty($flags)) { // The query doesn't match any flags so it will always fail anyway. return []; From 783f4d0a78707c7707b281c57e4420657a7303e2 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 22:34:37 +0200 Subject: [PATCH 3/3] SearchService.php: fix matchStrings not matching flags --- inc/Service/SearchService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/Service/SearchService.php b/inc/Service/SearchService.php index 1bfcf0f9..affca81c 100644 --- a/inc/Service/SearchService.php +++ b/inc/Service/SearchService.php @@ -138,7 +138,7 @@ class SearchService { private static function matchStrings(array $strings, array $fragments): array { return \array_filter($strings, function ($str) use ($fragments) { // Saves the last position. We use this to ensure the fragments are one after the other. - $last_ret = 0; + $last_ret = -1; foreach ($fragments as $fragment) { if ($last_ret + 1 > \strlen($fragment)) { // Cannot possibly match. @@ -147,7 +147,7 @@ class SearchService { $last_ret = \stripos($str, $fragment, $last_ret + 1); if ($last_ret === false) { - // Exclude flags that don't much even a single fragment. + // Exclude flags that don't match even a single fragment. return false; } }