1 | <?php |
||
25 | class Repository |
||
26 | { |
||
27 | /** |
||
28 | * @var Manager |
||
29 | */ |
||
30 | private $manager; |
||
31 | |||
32 | /** |
||
33 | * @var string Fully qualified class name |
||
34 | */ |
||
35 | private $className; |
||
36 | |||
37 | /** |
||
38 | * @var string Elasticsearch type name |
||
39 | */ |
||
40 | private $type; |
||
41 | |||
42 | /** |
||
43 | * Constructor. |
||
44 | * |
||
45 | * @param Manager $manager |
||
46 | * @param string $className |
||
47 | */ |
||
48 | public function __construct($manager, $className) |
||
64 | |||
65 | /** |
||
66 | * Returns elasticsearch manager used in the repository. |
||
67 | * |
||
68 | * @return Manager |
||
69 | */ |
||
70 | public function getManager() |
||
74 | |||
75 | /** |
||
76 | * @return array |
||
77 | */ |
||
78 | public function getType() |
||
82 | |||
83 | /** |
||
84 | * Returns a single document data by ID or null if document is not found. |
||
85 | * |
||
86 | * @param string $id Document ID to find |
||
87 | * |
||
88 | * @return object |
||
89 | */ |
||
90 | public function find($id) |
||
94 | |||
95 | /** |
||
96 | * Returns documents by a set of ids |
||
97 | * |
||
98 | * @param array $ids |
||
99 | * |
||
100 | * @return DocumentIterator The objects. |
||
101 | */ |
||
102 | public function findByIds(array $ids) |
||
130 | |||
131 | /** |
||
132 | * Finds documents by a set of criteria. |
||
133 | * |
||
134 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
135 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
136 | * @param int|null $limit Example: 5. |
||
137 | * @param int|null $offset Example: 30. |
||
138 | * |
||
139 | * @return array|DocumentIterator The objects. |
||
140 | */ |
||
141 | public function findBy( |
||
168 | |||
169 | /** |
||
170 | * Finds a single document by a set of criteria. |
||
171 | * |
||
172 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
173 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
174 | * |
||
175 | * @return object|null The object. |
||
176 | */ |
||
177 | public function findOneBy(array $criteria, array $orderBy = []) |
||
183 | |||
184 | /** |
||
185 | * Returns search instance. |
||
186 | * |
||
187 | * @return Search |
||
188 | */ |
||
189 | public function createSearch() |
||
193 | |||
194 | /** |
||
195 | * Executes given search. |
||
196 | * |
||
197 | * @param Search $search |
||
198 | * @param string $resultsType |
||
199 | * |
||
200 | * @return DocumentIterator|RawIterator|array |
||
201 | * |
||
202 | * @throws \Exception |
||
203 | */ |
||
204 | public function execute(Search $search, $resultsType = Result::RESULTS_OBJECT) |
||
208 | |||
209 | /** |
||
210 | * Counts documents by given search. |
||
211 | * |
||
212 | * @param Search $search |
||
213 | * @param array $params |
||
214 | * @param bool $returnRaw If set true returns raw response gotten from client. |
||
215 | * |
||
216 | * @return int|array |
||
217 | */ |
||
218 | public function count(Search $search, array $params = [], $returnRaw = false) |
||
239 | |||
240 | /** |
||
241 | * Removes a single document data by ID. |
||
242 | * |
||
243 | * @param string $id Document ID to remove. |
||
244 | * |
||
245 | * @return array |
||
246 | * |
||
247 | * @throws \LogicException |
||
248 | */ |
||
249 | public function remove($id) |
||
261 | |||
262 | /** |
||
263 | * Partial document update. |
||
264 | * |
||
265 | * @param string $id Document id to update. |
||
266 | * @param array $fields Fields array to update. |
||
267 | * @param string $script Groovy script to update fields. |
||
268 | * @param array $params Additional parameters to pass to the client. |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | public function update($id, array $fields = [], $script = null, array $params = []) |
||
293 | |||
294 | /** |
||
295 | * Resolves elasticsearch type by class name. |
||
296 | * |
||
297 | * @param string $className |
||
298 | * |
||
299 | * @return array |
||
300 | */ |
||
301 | private function resolveType($className) |
||
305 | |||
306 | /** |
||
307 | * Returns fully qualified class name. |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | public function getClassName() |
||
315 | } |
||
316 |