forked from leftypol/leftypol
Reviewed-on: leftypol/leftypol#143
This commit is contained in:
commit
00a4435a61
2 changed files with 6 additions and 4 deletions
|
|
@ -220,7 +220,7 @@ class UserPostQueries {
|
||||||
for ($i = 0; $i < \count($flags); $i++) {
|
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.
|
// 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.
|
// English lacks the words to express my feelings about it in a satisfying manner.
|
||||||
$flag_acc[] = "CONCAT('%<tinyboard>', :flag$i, '</tinyboard>%')";
|
$flag_acc[] = "CONCAT('%<tinyboard flag alt>', :flag$i, '</tinyboard>%')";
|
||||||
}
|
}
|
||||||
$where_acc[] = 'body_nomarkup LIKE (' . \implode(' OR ', $flag_acc) . ')';
|
$where_acc[] = 'body_nomarkup LIKE (' . \implode(' OR ', $flag_acc) . ')';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ class SearchService {
|
||||||
private static function matchStrings(array $strings, array $fragments): array {
|
private static function matchStrings(array $strings, array $fragments): array {
|
||||||
return \array_filter($strings, function ($str) use ($fragments) {
|
return \array_filter($strings, function ($str) use ($fragments) {
|
||||||
// Saves the last position. We use this to ensure the fragments are one after the other.
|
// 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) {
|
foreach ($fragments as $fragment) {
|
||||||
if ($last_ret + 1 > \strlen($fragment)) {
|
if ($last_ret + 1 > \strlen($fragment)) {
|
||||||
// Cannot possibly match.
|
// Cannot possibly match.
|
||||||
|
|
@ -147,7 +147,7 @@ class SearchService {
|
||||||
|
|
||||||
$last_ret = \stripos($str, $fragment, $last_ret + 1);
|
$last_ret = \stripos($str, $fragment, $last_ret + 1);
|
||||||
if ($last_ret === false) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -383,7 +383,9 @@ class SearchService {
|
||||||
|
|
||||||
$flags = [];
|
$flags = [];
|
||||||
if (!empty($filters->flag) && !empty($this->flag_map)) {
|
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)) {
|
if (empty($flags)) {
|
||||||
// The query doesn't match any flags so it will always fail anyway.
|
// The query doesn't match any flags so it will always fail anyway.
|
||||||
return [];
|
return [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue