eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchHitAdapter::getSlice PHP Method

getSlice() public method

Returns a slice of the results, as SearchHit objects.
public getSlice ( integer $offset, integer $length ) : eZ\Publish\API\Repository\Values\Content\Search\SearchHit[]
$offset integer The offset.
$length integer The length.
return eZ\Publish\API\Repository\Values\Content\Search\SearchHit[]
    public function getSlice($offset, $length)
    {
        $query = clone $this->query;
        $query->offset = $offset;
        $query->limit = $length;
        $query->performCount = false;
        $searchResult = $this->searchService->findLocations($query, $this->languageFilter);
        // Set count for further use if returned by search engine despite !performCount (Solr, ES)
        if (!isset($this->nbResults) && isset($searchResult->totalCount)) {
            $this->nbResults = $searchResult->totalCount;
        }
        return $searchResult->searchHits;
    }

Usage Example

 /**
  * Returns a slice of the results as Location objects.
  *
  * @param integer $offset The offset.
  * @param integer $length The length.
  *
  * @return \Truffo\eZContentDecoratorBundle\Decorator\ContentDecorator[]
  */
 public function getSlice($offset, $length)
 {
     $list = array();
     foreach (parent::getSlice($offset, $length) as $hit) {
         $list[] = $this->contentDecoratorFactory->getContentDecorator($hit->valueObject);
     }
     return $list;
 }