|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Xervice\Elasticsearch\Business; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use DataProvider\DocumentListDataProvider; |
|
8
|
|
|
use DataProvider\ElasticsearchResultSetDataProvider; |
|
9
|
|
|
use Elastica\Query; |
|
10
|
|
|
use Xervice\Core\Business\Model\Facade\AbstractFacade; |
|
11
|
|
|
use Xervice\DataProvider\Business\Model\DataProvider\DataProviderInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @method \Xervice\Elasticsearch\Business\ElasticsearchBusinessFactory getFactory() |
|
15
|
|
|
* @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig() |
|
16
|
|
|
*/ |
|
17
|
|
|
class ElasticsearchFacade extends AbstractFacade implements ElasticsearchFacadeInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Generate all indizes in elasticsearch |
|
21
|
|
|
* |
|
22
|
|
|
* @api |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function createIndizes(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this |
|
27
|
1 |
|
->getFactory() |
|
28
|
1 |
|
->createIndexer() |
|
29
|
1 |
|
->createIndizes(); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $dataProviderClass |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getMapping(string $dataProviderClass): array |
|
38
|
|
|
{ |
|
39
|
|
|
$this |
|
40
|
|
|
->getFactory() |
|
41
|
|
|
->createMappingConverter() |
|
42
|
|
|
->convertToMapping($dataProviderClass); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create a list of documents in elasticsearch |
|
47
|
|
|
* |
|
48
|
|
|
* @api |
|
49
|
|
|
* |
|
50
|
|
|
* @param \DataProvider\DocumentListDataProvider $listDataProvider |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function createDocuments(DocumentListDataProvider $listDataProvider): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this |
|
55
|
1 |
|
->getFactory() |
|
56
|
1 |
|
->createDocumentBuilder() |
|
57
|
1 |
|
->createDocuments($listDataProvider); |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Remove a list of documents in elasticsearch |
|
62
|
|
|
* |
|
63
|
|
|
* @api |
|
64
|
|
|
* |
|
65
|
|
|
* @param \DataProvider\DocumentListDataProvider $listDataProvider |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function deleteDocuments(DocumentListDataProvider $listDataProvider): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this |
|
70
|
1 |
|
->getFactory() |
|
71
|
1 |
|
->createDocumentCleaner() |
|
72
|
1 |
|
->deleteDocuments($listDataProvider); |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Send search request to elasticsearch |
|
77
|
|
|
* QueryExtenderPlugins can extend the query |
|
78
|
|
|
* ResultFormatterPlugins can format the result DataProvider |
|
79
|
|
|
* |
|
80
|
|
|
* @api |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $index |
|
83
|
|
|
* @param \Elastica\Query $query |
|
84
|
|
|
* @param array $queryExtender |
|
85
|
|
|
* @param array $resultFormatter |
|
86
|
|
|
* |
|
87
|
|
|
* @return \DataProvider\ElasticsearchResultSetDataProvider |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public function search( |
|
90
|
|
|
string $index, |
|
91
|
|
|
Query $query, |
|
92
|
|
|
array $queryExtender = [], |
|
93
|
|
|
array $resultFormatter = [] |
|
94
|
|
|
): ElasticsearchResultSetDataProvider { |
|
95
|
|
|
return $this |
|
96
|
1 |
|
->getFactory() |
|
97
|
1 |
|
->createSearch($queryExtender, $resultFormatter) |
|
98
|
1 |
|
->search($index, $query); |
|
99
|
|
|
} |
|
100
|
|
|
} |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: