SearchService.php: remove filtered out keywords and filters

This commit is contained in:
Zankaria 2025-07-13 01:54:47 +02:00
parent cef13f0b31
commit 45603467bc

View file

@ -288,19 +288,23 @@ class SearchService {
if ($filters->subject !== null) { if ($filters->subject !== null) {
list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->subject); list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->subject);
if (!empty($fragments) && $total_len >= 0) {
if ($total_len <= self::MAX_LENGTH_SUBJECT) { if ($total_len <= self::MAX_LENGTH_SUBJECT) {
$weighted->subject = $fragments; $weighted->subject = $fragments;
$weighted->weight = $wildcard_weight; $weighted->weight += $wildcard_weight;
}
} }
} }
if ($filters->name !== null) { if ($filters->name !== null) {
list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->name); list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->name);
if (!empty($fragments) && $total_len >= 0) {
if ($total_len <= self::MAX_LENGTH_NAME) { if ($total_len <= self::MAX_LENGTH_NAME) {
$weighted->name = $fragments; $weighted->name = $fragments;
$weighted->weight += $wildcard_weight; $weighted->weight += $wildcard_weight;
} }
} }
}
// No wildcard support, and obligatory anyway so it weights 0. // No wildcard support, and obligatory anyway so it weights 0.
$weighted->board = $filters->board; $weighted->board = $filters->board;
if ($filters->flag !== null) { if ($filters->flag !== null) {
@ -311,6 +315,7 @@ class SearchService {
list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->flag); list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($filters->flag);
if (!empty($fragments) && $total_len >= 0) {
// Add 2 to account for possible wildcards on the ends. // Add 2 to account for possible wildcards on the ends.
if ($total_len <= $max_flag_length + 2) { if ($total_len <= $max_flag_length + 2) {
$weighted->flag = $fragments; $weighted->flag = $fragments;
@ -318,11 +323,14 @@ class SearchService {
} }
} }
} }
}
$weighted->id = $filters->id; $weighted->id = $filters->id;
$weighted->thread = $filters->thread; $weighted->thread = $filters->thread;
if (!empty($filters->body)) { if (!empty($filters->body)) {
foreach ($filters->body as $keyword) { foreach ($filters->body as $keyword) {
list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($keyword); list($fragments, $total_len, $wildcard_weight) = self::filterAndWeight($keyword);
if (!empty($fragments) && $total_len >= 0) {
$content_weight = self::weightByContent($fragments); $content_weight = self::weightByContent($fragments);
$str_weight = $content_weight + $wildcard_weight; $str_weight = $content_weight + $wildcard_weight;
@ -332,6 +340,7 @@ class SearchService {
} }
} }
} }
}
return $weighted; return $weighted;
} }