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