/** * Search jobs. * * Jobs can be searched with a full text search (when search query is a string), * or with an extended search (when search query is an array). * * Full text search feature is turned off by default since Kue >=0.9.0. * Please {@link https://github.com/Automattic/kue#get-jobsearchq follow the Kue documentation} if you want to enable it. * * In case of extended search, the following array keys are recognized: * * - `from` _(required)_ - filters jobs with the specified ID range, starting with `from`; * - `to` _(required)_ - filters jobs with the specified ID range, ending with `to`; * - `state` - filters jobs by state, this field is required if `type` is also set; * - `type` - filters jobs by type; * - `order` - orders results by `asc` or `desc`. * * @param string|array $query Search query. * * @return bool|mixed API response or `false` if API request fails. * @throws \kop\kue\exceptions\ApiException If API request fails and {@link Client::$_throwExceptions} is enabled. * @throws \kop\kue\exceptions\ClientException If search request is composed wrong and {@link Client::$_throwExceptions} is enabled. * * @see https://github.com/Automattic/kue#get-jobsearchq * @see https://github.com/Automattic/kue#get-jobsfromtoorder * @see https://github.com/Automattic/kue#get-jobsstatefromtoorder * @see https://github.com/Automattic/kue#get-jobstypestatefromtoorder */ public function search($query) { // Search by query string if (is_string($query)) { return $this->client->request('GET', 'job/search', ['query' => ['q' => $query]]); } // Extended search if (is_array($query) && isset($query['from'], $query['to'])) { $requestPath = ''; if (in_array('order', $query)) { $requestPath = "/{$query['order']}" . $requestPath; } $requestPath = "/{$query['from']}..{$query['to']}" . $requestPath; if (in_array('state', $query)) { $requestPath = "/{$query['state']}" . $requestPath; } if (in_array('type', $query)) { $requestPath = "/{$query['type']}" . $requestPath; } return $this->client->request('GET', "jobs{$requestPath}"); } $this->client->getLogger()->error('Jobs search request is composed wrong!'); if ($this->client->getThrowExceptions()) { throw new ClientException('Jobs search request is composed wrong!'); } return false; }