|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Xervice\Elasticsearch\Business; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Elastica\Client; |
|
8
|
|
|
use Xervice\Core\Business\Model\Factory\AbstractBusinessFactory; |
|
9
|
|
|
use Xervice\Elasticsearch\Business\Collection\IndexCollection; |
|
10
|
|
|
use Xervice\Elasticsearch\Business\Model\Document\DocumentBuilder; |
|
11
|
|
|
use Xervice\Elasticsearch\Business\Model\Document\DocumentBuilderInterface; |
|
12
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\IndexBuilder; |
|
13
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\IndexBuilderInterface; |
|
14
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\MappingConverter; |
|
15
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\MappingConverterInterface; |
|
16
|
|
|
use Xervice\Elasticsearch\Business\Model\Indexer; |
|
17
|
|
|
use Xervice\Elasticsearch\Business\Model\IndexerInterface; |
|
18
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilder; |
|
19
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilderInterface; |
|
20
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverter; |
|
21
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverterInterface; |
|
22
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\Search; |
|
23
|
|
|
use Xervice\Elasticsearch\Business\Model\Search\SearchInterface; |
|
24
|
|
|
use Xervice\Elasticsearch\ElasticsearchDependencyProvider; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig() |
|
28
|
|
|
*/ |
|
29
|
|
|
class ElasticsearchBusinessFactory extends AbstractBusinessFactory |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @param array $queryExtenderPlugins |
|
33
|
|
|
* @param array $resultFormatterPlugins |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Search\SearchInterface |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function createSearch( |
|
38
|
|
|
array $queryExtenderPlugins, |
|
39
|
|
|
array $resultFormatterPlugins |
|
40
|
|
|
): SearchInterface { |
|
41
|
1 |
|
return new Search( |
|
42
|
1 |
|
$this->getClient(), |
|
43
|
1 |
|
$this->createQueryBuilder($queryExtenderPlugins), |
|
44
|
1 |
|
$this->createResultSetConverter($resultFormatterPlugins) |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param array $queryExtenderPlugins |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilderInterface |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function createQueryBuilder(array $queryExtenderPlugins): QueryBuilderInterface |
|
54
|
|
|
{ |
|
55
|
1 |
|
return new QueryBuilder( |
|
56
|
1 |
|
$queryExtenderPlugins |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param array $resultFormatterPlugins |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverterInterface |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function createResultSetConverter(array $resultFormatterPlugins): ResultSetConverterInterface |
|
66
|
|
|
{ |
|
67
|
1 |
|
return new ResultSetConverter( |
|
68
|
1 |
|
$resultFormatterPlugins |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Document\DocumentBuilderInterface |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function createDocumentBuilder(): DocumentBuilderInterface |
|
76
|
|
|
{ |
|
77
|
1 |
|
return new DocumentBuilder( |
|
78
|
1 |
|
$this->getClient() |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\IndexerInterface |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function createIndexer(): IndexerInterface |
|
86
|
|
|
{ |
|
87
|
1 |
|
return new Indexer( |
|
88
|
1 |
|
$this->getIndexProviderCollection(), |
|
89
|
1 |
|
$this->createIndexBuilder(), |
|
90
|
1 |
|
$this->createMappingConverter() |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Index\MappingConverterInterface |
|
96
|
|
|
*/ |
|
97
|
4 |
|
public function createMappingConverter(): MappingConverterInterface |
|
98
|
|
|
{ |
|
99
|
4 |
|
return new MappingConverter(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Index\IndexBuilderInterface |
|
104
|
|
|
*/ |
|
105
|
4 |
|
public function createIndexBuilder(): IndexBuilderInterface |
|
106
|
|
|
{ |
|
107
|
4 |
|
return new IndexBuilder( |
|
108
|
4 |
|
$this->getClient() |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return \Elastica\Client |
|
114
|
|
|
*/ |
|
115
|
4 |
|
public function getClient(): Client |
|
116
|
|
|
{ |
|
117
|
4 |
|
return $this->getDependency(ElasticsearchDependencyProvider::CLIENT); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return \Xervice\Elasticsearch\Business\Collection\IndexCollection |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function getIndexProviderCollection(): IndexCollection |
|
124
|
|
|
{ |
|
125
|
1 |
|
return $this->getDependency(ElasticsearchDependencyProvider::INDEX_PROVIDER); |
|
126
|
|
|
} |
|
127
|
|
|
} |