1 | <?php |
||
17 | class ElasticaAdapter implements AdapterInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var Query |
||
21 | */ |
||
22 | private $query; |
||
23 | |||
24 | /** |
||
25 | * @var \Elastica\ResultSet |
||
26 | */ |
||
27 | private $resultSet; |
||
28 | |||
29 | /** |
||
30 | * @var SearchableInterface |
||
31 | */ |
||
32 | private $searchable; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $options; |
||
38 | |||
39 | /** |
||
40 | * @var int|null |
||
41 | * |
||
42 | * Used to limit the number of totalHits returned by ES. |
||
43 | * For more information, see: https://github.com/whiteoctober/Pagerfanta/pull/213#issue-87631892 |
||
44 | */ |
||
45 | private $maxResults; |
||
46 | |||
47 | 5 | public function __construct(SearchableInterface $searchable, Query $query, array $options = array(), $maxResults = null) |
|
54 | |||
55 | /** |
||
56 | * Returns the number of results. |
||
57 | * |
||
58 | * @return integer The number of results. |
||
59 | */ |
||
60 | 3 | public function getNbResults() |
|
61 | { |
||
62 | 3 | if (!$this->resultSet) { |
|
63 | 2 | $totalHits = $this->searchable->count($this->query); |
|
64 | } else { |
||
65 | 1 | $totalHits = $this->resultSet->getTotalHits(); |
|
66 | } |
||
67 | |||
68 | 3 | if (null === $this->maxResults) { |
|
69 | 1 | return $totalHits; |
|
70 | } |
||
71 | |||
72 | 2 | return min($totalHits, $this->maxResults); |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Returns the Elastica ResultSet. Will return null if getSlice has not yet been |
||
77 | * called. |
||
78 | * |
||
79 | * @return \Elastica\ResultSet|null |
||
80 | */ |
||
81 | 2 | public function getResultSet() |
|
85 | |||
86 | /** |
||
87 | * Returns an slice of the results. |
||
88 | * |
||
89 | * @param integer $offset The offset. |
||
90 | * @param integer $length The length. |
||
91 | * |
||
92 | * @return array|\Traversable The slice. |
||
93 | */ |
||
94 | 3 | public function getSlice($offset, $length) |
|
101 | } |
||
102 |