-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
ElasticsearchAdapter.php
50 lines (39 loc) · 1.42 KB
/
ElasticsearchAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Schranz\Search\SEAL\Adapter\Elasticsearch;
use Elastic\Elasticsearch\Client;
use Schranz\Search\SEAL\Adapter\AdapterInterface;
use Schranz\Search\SEAL\Adapter\IndexerInterface;
use Schranz\Search\SEAL\Adapter\SchemaManagerInterface;
use Schranz\Search\SEAL\Adapter\SearcherInterface;
final class ElasticsearchAdapter implements AdapterInterface
{
private readonly SchemaManagerInterface $schemaManager;
private readonly IndexerInterface $indexer;
private readonly SearcherInterface $searcher;
public function __construct(
Client $client,
?SchemaManagerInterface $schemaManager = null,
?IndexerInterface $indexer = null,
?SearcherInterface $searcher = null,
) {
if ($client->getAsync()) {
throw new \RuntimeException('Currently only synchronous client is supported.');
}
$this->schemaManager = $schemaManager ?? new ElasticsearchSchemaManager($client);
$this->indexer = $indexer ?? new ElasticsearchIndexer($client);
$this->searcher = $searcher ?? new ElasticsearchSearcher($client);
}
public function getSchemaManager(): SchemaManagerInterface
{
return $this->schemaManager;
}
public function getIndexer(): IndexerInterface
{
return $this->indexer;
}
public function getSearcher(): SearcherInterface
{
return $this->searcher;
}
}