/** * Returns a slice of the results, as SearchHit objects. * * @param int $offset The offset * @param int $length 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->findService->findContentInfo($query); // 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; }
public function testGetSlice() { $offset = 20; $limit = 25; $nbResults = 123; $query = new Query(['offset' => 5, 'limit' => 10]); $searchQuery = clone $query; $searchQuery->offset = $offset; $searchQuery->limit = $limit; $searchQuery->performCount = false; $hits = [new SearchHit(['valueObject' => 'Content'])]; $searchResult = new SearchResult(['searchHits' => $hits, 'totalCount' => $nbResults]); $this->findService->expects($this->once())->method('findContent')->with($this->equalTo($searchQuery))->will($this->returnValue($searchResult)); $adapter = $this->getAdapter($query); $this->assertSame($this->getExpectedSlice($hits), $adapter->getSlice($offset, $limit)); $this->assertSame($nbResults, $adapter->getNbResults()); }