SearchService.php: limit the searchable boards

This commit is contained in:
Zankaria 2025-05-23 22:31:35 +02:00
parent a99cc34f7e
commit b4d5f23e78

View file

@ -37,6 +37,7 @@ class SearchService {
private float $max_weight;
private int $max_query_length;
private int $post_limit;
private array $searchable_board_uris;
private static function truncateQuery(string $text, int $byteLimit): ?string {
@ -242,16 +243,30 @@ class SearchService {
}
/**
* @param LogDriver $log Log river.
* @param UserPostQueries $user_queries User posts queries.
* @param ?flag_map $max_flag_length The key-value map of user flags, or null to disable flag search.
* @param ?array $flag_map The key-value map of user flags, or null to disable flag search.
* @param float $max_weight The maximum weight of the parsed user query. Body filters that go beyond this limit are discarded.
* @param int $max_query_length Maximum length of the raw input query before it's truncated.
* @param int $post_limit Maximum number of results.
* @param array $searchable_board_uris The uris of the board that can be searched.
*/
public function __construct(LogDriver $log, UserPostQueries $user_queries, ?array $flag_map, float $max_weight, int $max_query_length, int $post_limit) {
public function __construct(
LogDriver $log,
UserPostQueries $user_queries,
?array $flag_map,
float $max_weight,
int $max_query_length,
int $post_limit,
array $searchable_board_uris
) {
$this->log = $log;
$this->user_queries = $user_queries;
$this->flag_map = $flag_map;
$this->max_weight = $max_weight;
$this->max_query_length = $max_query_length;
$this->post_limit = $post_limit;
$this->searchable_board_uris = $searchable_board_uris;
}
/**
@ -329,8 +344,7 @@ class SearchService {
return [];
}
$valid_uris = listBoards(true);
if (!\in_array($board, $valid_uris)) {
if (!\in_array($board, $this->searchable_board_uris)) {
return [];
}