/**
  * 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);
 }
Пример #2
0
 /**
  * Executes a search and return results
  *
  * @param array $searchBody              The body of the search request
  * @param int   $resultsType             Bitmask value determining how the results are returned
  * @param array $additionalRequestParams Additional params to pass to the ES client's search() method
  * @param int   $totalHits               The total hits of the query response
  * @return mixed
  */
 public function find(array $searchBody, $resultsType = Finder::RESULTS_OBJECT, array $additionalRequestParams = [], &$totalHits = null)
 {
     return $this->finder->find([$this->documentClass], $searchBody, $resultsType, $additionalRequestParams, $totalHits);
 }