/** * Perform a search and return record collection. * * @param AbstractQuery $query Search query * @param integer $offset Search offset * @param integer $limit Search limit * @param ParamBag $params Search backend parameters * * @return RecordCollectionInterface */ public function search(AbstractQuery $query, $offset, $limit, ParamBag $params = null) { $baseParams = $this->getQueryBuilder()->build($query); if (null !== $params) { $baseParams->mergeWith($params); } $args = $this->paramBagToArray($baseParams); try { $response = $this->connector->query($args, $offset, $limit); // Apply default search if necessary: if ($response['recordCount'] < 1 && isset($this->defaultSearch)) { $args['search'] = $this->defaultSearch; $response = $this->connector->query($args, $offset, $limit); } } catch (\Exception $e) { throw new BackendException($e->getMessage(), $e->getCode(), $e); } $collection = $this->createRecordCollection($response); $this->injectSourceIdentifier($collection); return $collection; }