1 | <?php |
||
22 | class RawPaginatorAdapter implements PaginatorAdapterInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var SearchableInterface the object to search in |
||
26 | */ |
||
27 | private $searchable; |
||
28 | |||
29 | /** |
||
30 | * @var Query the query to search |
||
31 | */ |
||
32 | private $query; |
||
33 | |||
34 | /** |
||
35 | * @var array search options |
||
36 | */ |
||
37 | private $options; |
||
38 | |||
39 | /** |
||
40 | * @var int the number of hits |
||
41 | */ |
||
42 | private $totalHits; |
||
43 | |||
44 | /** |
||
45 | * @var array for the aggregations |
||
46 | */ |
||
47 | private $aggregations; |
||
48 | |||
49 | /** |
||
50 | * @var array for the suggesters |
||
51 | */ |
||
52 | private $suggests; |
||
53 | |||
54 | /** |
||
55 | * @var float |
||
56 | */ |
||
57 | private $maxScore; |
||
58 | |||
59 | /** |
||
60 | * @see PaginatorAdapterInterface::__construct |
||
61 | * |
||
62 | * @param SearchableInterface $searchable the object to search in |
||
63 | * @param Query $query the query to search |
||
64 | * @param array $options |
||
65 | */ |
||
66 | 9 | public function __construct(SearchableInterface $searchable, Query $query, array $options = []) |
|
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function getResults($offset, $itemCountPerPage) |
||
80 | |||
81 | /** |
||
82 | * Returns the number of results. |
||
83 | * |
||
84 | * If genuineTotal is provided as true, total hits is returned from the |
||
85 | * hits.total value from the search results instead of just returning |
||
86 | * the requested size. |
||
87 | * |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | 2 | public function getTotalHits($genuineTotal = false) |
|
91 | { |
||
92 | 2 | if (!isset($this->totalHits)) { |
|
93 | 2 | $this->totalHits = $this->searchable->count($this->query); |
|
94 | } |
||
95 | |||
96 | 2 | return $this->query->hasParam('size') && !$genuineTotal |
|
97 | 1 | ? min($this->totalHits, (int) $this->query->getParam('size')) |
|
98 | 2 | : $this->totalHits; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | 1 | public function getAggregations() |
|
105 | { |
||
106 | 1 | if (!isset($this->aggregations)) { |
|
107 | 1 | $this->aggregations = $this->searchable->search($this->query)->getAggregations(); |
|
108 | } |
||
109 | |||
110 | 1 | return $this->aggregations; |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 1 | public function getSuggests() |
|
117 | { |
||
118 | 1 | if (!isset($this->suggests)) { |
|
119 | 1 | $this->suggests = $this->searchable->search($this->query)->getSuggests(); |
|
120 | } |
||
121 | |||
122 | 1 | return $this->suggests; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return float |
||
127 | */ |
||
128 | 1 | public function getMaxScore() |
|
129 | { |
||
130 | 1 | if (!isset($this->maxScore)) { |
|
131 | 1 | $this->maxScore = $this->searchable->search($this->query)->getMaxScore(); |
|
132 | } |
||
133 | |||
134 | 1 | return $this->maxScore; |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * Returns the Query. |
||
139 | * |
||
140 | * @return Query the search query |
||
141 | */ |
||
142 | 1 | public function getQuery() |
|
143 | { |
||
144 | 1 | return $this->query; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Returns the paginated results. |
||
149 | * |
||
150 | * @param int $offset |
||
151 | * @param int $itemCountPerPage |
||
152 | * |
||
153 | * @throws \InvalidArgumentException |
||
154 | * |
||
155 | * @return ResultSet |
||
156 | */ |
||
157 | protected function getElasticaResults($offset, $itemCountPerPage) |
||
185 | } |
||
186 |