/** * Return results for this page only * * @param int $offset * @param int $count * @param string $sortField * @param string $sortDir * @return mixed */ public function getResults($offset, $count, $sortField = null, $sortDir = 'asc') { $searchBody = $this->searchBody; $searchBody['from'] = $offset; $searchBody['size'] = $count; if ($sortField) { if (!isset($searchBody['sort'])) { $searchBody['sort'] = []; } // If sorting is set in the request in advance and the main sort field is the same as the one set for KNP, remove it if (isset($searchBody['sort'][0]) && key($searchBody['sort'][0]) === $sortField) { array_shift($searchBody['sort']); } // Keep any preliminary set order as a secondary order to the query array_unshift($searchBody['sort'], [$sortField => ['order' => $sortDir]]); } return $this->finder->find($this->documentClasses, $searchBody, $this->resultsType, $this->additionalRequestParams, $this->totalHits); }
/** * Returns the number of records matching the given query * * @param array $searchBody * @param array $additionalRequestParams * @return int */ public function count(array $searchBody, array $additionalRequestParams = []) { return $this->finder->count([$this->documentClass], $searchBody, $additionalRequestParams); }
/** * Returns results from a scroll request * @return mixed */ public function getNextScrollResults() { // Execute a scroll request $results = $this->finder->scroll($this->documentClasses, $this->scrollId, Finder::SCROLL_TIME, $this->resultsType, $this->totalHits); return $results; }
/** * Returns a single document data by ID or null if document is not found. * * @param string $id Document Id to find. * @param int $resultType Result type returned. * * @return DocumentInterface|null */ public function getById($id, $resultType = Finder::RESULTS_OBJECT) { return $this->finder->get($this->metadata->getShortClassName(), $id, $resultType); }