diff --git a/inc/Service/SearchService.php b/inc/Service/SearchService.php index 93ea745d..443edd44 100644 --- a/inc/Service/SearchService.php +++ b/inc/Service/SearchService.php @@ -2,7 +2,7 @@ namespace Vichan\Service; use Vichan\Data\Driver\LogDriver; -use Vichan\Data\{FiltersParseResult, UserPostQueries, SearchFilters}; +use Vichan\Data\{FiltersParseResult, UserPostQueries, SearchFilters, SearchQueries}; class SearchService { @@ -33,6 +33,7 @@ class SearchService { private LogDriver $log; private UserPostQueries $user_queries; + private SearchQueries $search_queries; private ?array $flag_map; private float $max_weight; private int $max_query_length; @@ -245,6 +246,7 @@ class SearchService { /** * @param LogDriver $log Log river. * @param UserPostQueries $user_queries User posts queries. + * @param SearchQueries $search_queries Search queries for flood detection. * @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. @@ -254,6 +256,7 @@ class SearchService { public function __construct( LogDriver $log, UserPostQueries $user_queries, + SearchQueries $search_queries, ?array $flag_map, float $max_weight, int $max_query_length, @@ -262,6 +265,7 @@ class SearchService { ) { $this->log = $log; $this->user_queries = $user_queries; + $this->search_queries = $search_queries; $this->flag_map = $flag_map; $this->max_weight = $max_weight; $this->max_query_length = $max_query_length; @@ -375,6 +379,17 @@ class SearchService { ); } + /** + * Check if the IP-query pair passes the limit. + * + * @param string $ip Source IP. + * @param string $phrase The search query. + * @return bool True if the request goes over the limit. + */ + public function checkFlood(string $ip, string $raw_query) { + return $this->search_queries->checkFlood($ip, $raw_query); + } + /** * Returns the uris of the boards that may be searched. */