1 | <?php |
||
31 | class Manganel |
||
32 | { |
||
33 | |||
34 | const DefaultIndexId = 'manganel'; |
||
35 | |||
36 | public $decorators = [ |
||
37 | SearchCriteria::class => [ |
||
38 | ConditionDecorator::class, |
||
39 | ConditionsDecorator::class, |
||
40 | ScrollDecorator::class, |
||
41 | SearchDecorator::class, |
||
42 | ] |
||
43 | ]; |
||
44 | public $hosts = [ |
||
45 | 'localhost:9200' |
||
46 | ]; |
||
47 | public $auth = null; |
||
48 | public $username = ''; |
||
49 | public $password = ''; |
||
50 | public $params = []; |
||
51 | |||
52 | /** |
||
53 | * TODO Enforce lowercase |
||
54 | */ |
||
55 | public $index = 'my_index'; |
||
56 | public $indexId = self::DefaultIndexId; |
||
57 | |||
58 | /** |
||
59 | * Whether to use refresh option when indexing document. |
||
60 | * NOTE: Due to performance reasons, this should be set to `true` only when |
||
61 | * really necessary - so it can be also callback. |
||
62 | * |
||
63 | * Callback function signature: |
||
64 | * ``` |
||
65 | * function(AnnotatedInterface $model) |
||
66 | * ``` |
||
67 | * @var string|Closure |
||
68 | */ |
||
69 | public $refresh = false; |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @var Client |
||
74 | */ |
||
75 | private $client = null; |
||
76 | |||
77 | /** |
||
78 | * Dependency injection container |
||
79 | * @var EmbeDi |
||
80 | */ |
||
81 | private $di = null; |
||
82 | |||
83 | /** |
||
84 | * Instances of manganel |
||
85 | * @var Manganel[] |
||
86 | */ |
||
87 | private static $mnl = []; |
||
88 | |||
89 | /** |
||
90 | * Hash map of class name to id. This is to reduce overhead of Mangan::fromModel() |
||
91 | * @var string[] |
||
92 | */ |
||
93 | private static $classToId = []; |
||
94 | |||
95 | /** |
||
96 | * Class constructor |
||
97 | * @codeCoverageIgnore This is implicitly tested |
||
98 | * @param string $indexId |
||
99 | */ |
||
100 | public function __construct($indexId = self::DefaultIndexId) |
||
115 | |||
116 | /** |
||
117 | * @codeCoverageIgnore This is implicitly tested |
||
118 | * @param AnnotatedInterface $model |
||
119 | * @return static |
||
120 | */ |
||
121 | public static function create(AnnotatedInterface $model) |
||
135 | |||
136 | /** |
||
137 | * Get flyweight instance of Manganel component. |
||
138 | * Only one instance will be created for each `$indexId`. |
||
139 | * |
||
140 | * @codeCoverageIgnore This is implicitly tested |
||
141 | * @new |
||
142 | * @param string $indexId |
||
143 | * @return Manganel |
||
144 | */ |
||
145 | public static function fly($indexId = self::DefaultIndexId) |
||
157 | |||
158 | /** |
||
159 | * @codeCoverageIgnore This is implicitly tested |
||
160 | */ |
||
161 | public function init() |
||
165 | |||
166 | /** |
||
167 | * Drop current index |
||
168 | * @return bool |
||
169 | */ |
||
170 | 1 | public function drop() |
|
182 | |||
183 | /** |
||
184 | * @codeCoverageIgnore This is implicitly tested |
||
185 | * @return Client |
||
186 | */ |
||
187 | public function getClient() |
||
203 | |||
204 | } |
||
205 |