Merge pull request 'Fix #136: remove filtered out keywords and filters' (#137) from board-search-too-broad into config

Reviewed-on: leftypol/leftypol#137
This commit is contained in:
Zankaria 2025-07-12 19:00:17 -05:00
commit 46a53aa483

View file

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