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) . ')';
}
diff --git a/inc/Service/SearchService.php b/inc/Service/SearchService.php
index 8a1b3742..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;
}
}
@@ -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 [];