1 | <?php |
||
38 | class Manganel |
||
39 | { |
||
40 | |||
41 | const DefaultIndexId = 'manganel'; |
||
42 | |||
43 | public $decorators = [ |
||
44 | SearchCriteria::class => [ |
||
45 | ConditionDecorator::class, |
||
46 | ConditionsDecorator::class, |
||
47 | ScrollDecorator::class, |
||
48 | SearchDecorator::class, |
||
49 | InDecorator::class, |
||
50 | SimpleTermDecorator::class, |
||
51 | BoostDecorator::class, |
||
52 | PrefixQueryDecorator::class, |
||
53 | ] |
||
54 | ]; |
||
55 | public $hosts = [ |
||
56 | 'localhost:9200' |
||
57 | ]; |
||
58 | public $auth = null; |
||
59 | public $username = ''; |
||
60 | public $password = ''; |
||
61 | public $params = []; |
||
62 | |||
63 | /** |
||
64 | * TODO Enforce lowercase |
||
65 | */ |
||
66 | public $index = 'my_index'; |
||
67 | public $indexId = self::DefaultIndexId; |
||
68 | |||
69 | /** |
||
70 | * Whether to use refresh option when indexing document. |
||
71 | * NOTE: Due to performance reasons, this should be set to `true` only when |
||
72 | * really necessary - so it can be also callback. |
||
73 | * |
||
74 | * Callback function signature: |
||
75 | * ``` |
||
76 | * function(AnnotatedInterface $model) |
||
77 | * ``` |
||
78 | * @var string|Closure |
||
79 | */ |
||
80 | public $refresh = false; |
||
81 | |||
82 | /** |
||
83 | * |
||
84 | * @var Client |
||
85 | */ |
||
86 | private $client = null; |
||
87 | |||
88 | /** |
||
89 | * Dependency injection container |
||
90 | * @var EmbeDi |
||
91 | */ |
||
92 | private $di = null; |
||
93 | |||
94 | /** |
||
95 | * Version number holder |
||
96 | * @var string |
||
97 | */ |
||
98 | private static $_version = null; |
||
99 | |||
100 | /** |
||
101 | * Instances of manganel |
||
102 | * @var Manganel[] |
||
103 | */ |
||
104 | private static $mnl = []; |
||
105 | |||
106 | /** |
||
107 | * Hash map of class name to id. This is to reduce overhead of Mangan::fromModel() |
||
108 | * @var string[] |
||
109 | */ |
||
110 | private static $classToId = []; |
||
111 | |||
112 | /** |
||
113 | * Profiler instance |
||
114 | * @var ProfilerInterface |
||
115 | */ |
||
116 | private $profiler = null; |
||
117 | |||
118 | /** |
||
119 | * Class constructor |
||
120 | * @codeCoverageIgnore This is implicitly tested |
||
121 | * @param string $indexId |
||
122 | */ |
||
123 | public function __construct($indexId = self::DefaultIndexId) |
||
138 | |||
139 | /** |
||
140 | * @codeCoverageIgnore This is implicitly tested |
||
141 | * @param AnnotatedInterface $model |
||
142 | * @return static |
||
143 | */ |
||
144 | public static function create(AnnotatedInterface $model) |
||
158 | |||
159 | /** |
||
160 | * Get flyweight instance of Manganel component. |
||
161 | * Only one instance will be created for each `$indexId`. |
||
162 | * |
||
163 | * @codeCoverageIgnore This is implicitly tested |
||
164 | * @new |
||
165 | * @param string $indexId |
||
166 | * @return Manganel |
||
167 | */ |
||
168 | public static function fly($indexId = self::DefaultIndexId) |
||
180 | |||
181 | /** |
||
182 | * @codeCoverageIgnore This is implicitly tested |
||
183 | */ |
||
184 | public function init() |
||
188 | |||
189 | /** |
||
190 | * Get mangan version |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getVersion() |
||
201 | |||
202 | /** |
||
203 | * Drop current index |
||
204 | * @return bool |
||
205 | */ |
||
206 | 1 | public function drop() |
|
218 | |||
219 | /** |
||
220 | * @codeCoverageIgnore This is implicitly tested |
||
221 | * @return Client |
||
222 | */ |
||
223 | public function getClient() |
||
239 | |||
240 | /** |
||
241 | * Get profiler instance. This is guaranted, if not configured will return NullProfiller. |
||
242 | * @see NullProfiler |
||
243 | * @return ProfilerInterface |
||
244 | */ |
||
245 | 33 | public function getProfiler() |
|
257 | |||
258 | /** |
||
259 | * Set profiler instance |
||
260 | * @param ProfilerInterface $profiller |
||
261 | * @return static |
||
262 | */ |
||
263 | public function setProfiler(ProfilerInterface $profiller) |
||
268 | |||
269 | } |
||
270 |