1 | <?php |
||
44 | class Manganel |
||
45 | { |
||
46 | |||
47 | const DefaultIndexId = 'manganel'; |
||
48 | |||
49 | public $decorators = [ |
||
50 | SearchCriteria::class => [ |
||
51 | SelectDecorator::class, |
||
52 | ConditionDecorator::class, |
||
53 | ConditionsDecorator::class, |
||
54 | ScrollDecorator::class, |
||
55 | SearchDecorator::class, |
||
56 | InDecorator::class, |
||
57 | OrDecorator::class, |
||
58 | NotDecorator::class, |
||
59 | RangeDecorator::class, |
||
60 | SimpleTermDecorator::class, |
||
61 | BoostDecorator::class, |
||
62 | PrefixQueryDecorator::class, |
||
63 | MoreLikeThisDecorator::class |
||
64 | ] |
||
65 | ]; |
||
66 | public $hosts = [ |
||
67 | 'localhost:9200' |
||
68 | ]; |
||
69 | public $auth = null; |
||
70 | public $username = ''; |
||
71 | public $password = ''; |
||
72 | public $params = []; |
||
73 | |||
74 | /** |
||
75 | * TODO Enforce lowercase |
||
76 | */ |
||
77 | public $index = 'my_index'; |
||
78 | public $indexId = self::DefaultIndexId; |
||
79 | |||
80 | /** |
||
81 | * Whether to use refresh option when indexing document. |
||
82 | * NOTE: Due to performance reasons, this should be set to `true` only when |
||
83 | * really necessary - so it can be also callback. |
||
84 | * |
||
85 | * Callback function signature: |
||
86 | * ``` |
||
87 | * function(AnnotatedInterface $model) |
||
88 | * ``` |
||
89 | * @var string|Closure |
||
90 | */ |
||
91 | public $refresh = false; |
||
92 | |||
93 | /** |
||
94 | * |
||
95 | * @var Client |
||
96 | */ |
||
97 | private $client = null; |
||
98 | |||
99 | /** |
||
100 | * Dependency injection container |
||
101 | * @var EmbeDi |
||
102 | */ |
||
103 | private $di = null; |
||
104 | |||
105 | /** |
||
106 | * Version number holder |
||
107 | * @var string |
||
108 | */ |
||
109 | private static $_version = null; |
||
110 | |||
111 | /** |
||
112 | * Instances of manganel |
||
113 | * @var Manganel[] |
||
114 | */ |
||
115 | private static $mnl = []; |
||
116 | |||
117 | /** |
||
118 | * Hash map of class name to id. This is to reduce overhead of Mangan::fromModel() |
||
119 | * @var string[] |
||
120 | */ |
||
121 | private static $classToId = []; |
||
122 | |||
123 | /** |
||
124 | * Profiler instance |
||
125 | * @var ProfilerInterface |
||
126 | */ |
||
127 | private $profiler = null; |
||
128 | |||
129 | /** |
||
130 | * Class constructor |
||
131 | * @codeCoverageIgnore This is implicitly tested |
||
132 | * @param string $indexId |
||
133 | */ |
||
134 | public function __construct($indexId = self::DefaultIndexId) |
||
153 | |||
154 | /** |
||
155 | * @codeCoverageIgnore This is implicitly tested |
||
156 | * @param AnnotatedInterface $model |
||
157 | * @return static |
||
158 | */ |
||
159 | public static function create(AnnotatedInterface $model) |
||
173 | |||
174 | /** |
||
175 | * Get flyweight instance of Manganel component. |
||
176 | * Only one instance will be created for each `$indexId`. |
||
177 | * |
||
178 | * @codeCoverageIgnore This is implicitly tested |
||
179 | * @new |
||
180 | * @param string $indexId |
||
181 | * @return Manganel |
||
182 | */ |
||
183 | public static function fly($indexId = self::DefaultIndexId) |
||
195 | |||
196 | /** |
||
197 | * @codeCoverageIgnore This is implicitly tested |
||
198 | */ |
||
199 | public function init() |
||
203 | |||
204 | /** |
||
205 | * Get mangan version |
||
206 | * @return string |
||
207 | */ |
||
208 | public function getVersion() |
||
216 | |||
217 | /** |
||
218 | * Drop current index |
||
219 | * @return bool |
||
220 | */ |
||
221 | 1 | public function drop() |
|
233 | |||
234 | /** |
||
235 | * @codeCoverageIgnore This is implicitly tested |
||
236 | * @return Client |
||
237 | */ |
||
238 | public function getClient() |
||
254 | |||
255 | /** |
||
256 | * Get profiler instance. This is guaranted, if not configured will return NullProfiller. |
||
257 | * @see NullProfiler |
||
258 | * @return ProfilerInterface |
||
259 | */ |
||
260 | 24 | public function getProfiler() |
|
272 | |||
273 | /** |
||
274 | * Set profiler instance |
||
275 | * @param ProfilerInterface $profiller |
||
276 | * @return static |
||
277 | */ |
||
278 | public function setProfiler(ProfilerInterface $profiller) |
||
283 | |||
284 | } |
||
285 |