Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ContentSearchHitAdapter.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Pagination\Pagerfanta;
8
9 use eZ\Publish\API\Repository\Values\Content\Query;
10 use eZ\Publish\API\Repository\SearchService;
11 use Pagerfanta\Adapter\AdapterInterface;
12
17 class ContentSearchHitAdapter implements AdapterInterface
18 {
20 private $query;
21
23 private $searchService;
24
26 private $languageFilter;
27
29 private $nbResults;
30
31 public function __construct(
32 Query $query,
33 SearchService $searchService,
34 array $languageFilter = []
35 ) {
36 $this->query = $query;
37 $this->searchService = $searchService;
38 $this->languageFilter = $languageFilter;
39 }
40
46 public function getNbResults()
47 {
48 if (isset($this->nbResults)) {
49 return $this->nbResults;
50 }
51
52 $countQuery = clone $this->query;
53 $countQuery->limit = 0;
54
55 $searchResult = $this->searchService->findContent(
56 $countQuery,
57 $this->languageFilter
58 );
59
60 return $this->nbResults = $searchResult->totalCount;
61 }
62
71 public function getSlice($offset, $length)
72 {
73 $query = clone $this->query;
74 $query->offset = $offset;
75 $query->limit = $length;
76 $query->performCount = false;
77
78 $searchResult = $this->searchService->findContent($query, $this->languageFilter);
79
80 // Set count for further use if returned by search engine despite !performCount (Solr, ES)
81 if (!isset($this->nbResults) && isset($searchResult->totalCount)) {
82 $this->nbResults = $searchResult->totalCount;
83 }
84
85 return $searchResult->searchHits;
86 }
87 }
eZ\Publish\API\Repository\Values\Content\Query
This class is used to perform a Content query.
Definition: API/Repository/Values/Content/Query.php:15
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter
Pagerfanta adapter for eZ Publish content search.
Definition: ContentSearchHitAdapter.php:18
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\$query
$query
Definition: ContentSearchHitAdapter.php:20
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\$nbResults
$nbResults
Definition: ContentSearchHitAdapter.php:29
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\$languageFilter
$languageFilter
Definition: ContentSearchHitAdapter.php:26
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\getNbResults
getNbResults()
Returns the number of results.
Definition: ContentSearchHitAdapter.php:46
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\getSlice
getSlice($offset, $length)
Returns a slice of the results, as SearchHit objects.
Definition: ContentSearchHitAdapter.php:71
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\$searchService
$searchService
Definition: ContentSearchHitAdapter.php:23
eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchHitAdapter\__construct
__construct(Query $query, SearchService $searchService, array $languageFilter=[])
Definition: ContentSearchHitAdapter.php:31
eZ\Publish\API\Repository\SearchService
Search service.
Definition: API/Repository/SearchService.php:17
eZ\Publish\Core\Pagination\Pagerfanta
Definition: ContentSearchAdapter.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.