|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/elasticsearch7-adapter project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Daikon\Elasticsearch7\ReadModel; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Elasticsearch7\Query\Elasticsearch7Query; |
|
12
|
|
|
use Daikon\Elasticsearch7\Query\IdsQuery; |
|
13
|
|
|
use Daikon\ReadModel\Query\QueryInterface; |
|
14
|
|
|
use Daikon\ReadModel\Repository\RepositoryInterface; |
|
15
|
|
|
use Daikon\ReadModel\Repository\RepositoryMap; |
|
16
|
|
|
use Daikon\ReadModel\Storage\StorageResultInterface; |
|
17
|
|
|
|
|
18
|
|
|
abstract class Elasticsearch7Collection |
|
19
|
|
|
{ |
|
20
|
|
|
protected RepositoryInterface $repository; |
|
21
|
|
|
|
|
22
|
|
|
abstract public function __construct(RepositoryMap $repositoryMap); |
|
23
|
|
|
|
|
24
|
|
|
public function byId(string $id): StorageResultInterface |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->repository->findById($id); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function byIds(array $ids, int $from = 0, int $size = 50): StorageResultInterface |
|
30
|
|
|
{ |
|
31
|
|
|
$query = IdsQuery::fromNative($ids); |
|
32
|
|
|
return $this->repository->search($query, $from, $size); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** @param array|QueryInterface $query */ |
|
36
|
|
|
public function search($query, int $from = 0, int $size = 50): StorageResultInterface |
|
37
|
|
|
{ |
|
38
|
|
|
if (is_array($query)) { |
|
39
|
|
|
$query = Elasticsearch7Query::fromNative($query); |
|
40
|
|
|
}; |
|
41
|
|
|
|
|
42
|
|
|
return $this->repository->search($query, $from, $size); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** @param array|QueryInterface $query */ |
|
46
|
|
|
public function walk($query, callable $callback, int $size = 50): void |
|
47
|
|
|
{ |
|
48
|
|
|
if (is_array($query)) { |
|
49
|
|
|
$query = Elasticsearch7Query::fromNative($query); |
|
50
|
|
|
}; |
|
51
|
|
|
|
|
52
|
|
|
$this->repository->walk($query, $callback, $size); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** @param array|QueryInterface $query */ |
|
56
|
|
|
public function selectOne($query): StorageResultInterface |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->search($query, 0, 1); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|