1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.SearchIndexManager = exports.SearchIndex = void 0;
|
4 | const utilities_1 = require("./utilities");
|
5 | const bindingutilities_1 = require("./bindingutilities");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class SearchIndex {
|
13 | |
14 |
|
15 |
|
16 | constructor(data) {
|
17 | this.uuid = data.uuid;
|
18 | this.name = data.name;
|
19 | this.sourceName = data.sourceName;
|
20 | this.type = data.type;
|
21 | this.params = data.params;
|
22 | this.sourceUuid = data.sourceUuid;
|
23 | this.sourceParams = data.sourceParams;
|
24 | this.sourceType = data.sourceType;
|
25 | this.planParams = data.planParams;
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | static _toCppData(data) {
|
31 | return {
|
32 | uuid: data.uuid,
|
33 | name: data.name,
|
34 | type: data.type,
|
35 | params_json: JSON.stringify(data.params),
|
36 | source_uuid: data.sourceUuid,
|
37 | source_name: data.sourceName,
|
38 | source_type: data.sourceType,
|
39 | source_params_json: JSON.stringify(data.sourceParams),
|
40 | plan_params_json: JSON.stringify(data.planParams),
|
41 | };
|
42 | }
|
43 | |
44 |
|
45 |
|
46 | static _fromCppData(data) {
|
47 | const idx = new SearchIndex({
|
48 | uuid: data.uuid,
|
49 | name: data.name,
|
50 | type: data.type,
|
51 | params: {},
|
52 | sourceUuid: data.source_uuid,
|
53 | sourceName: data.source_name,
|
54 | sourceType: data.source_type,
|
55 | sourceParams: {},
|
56 | planParams: {},
|
57 | });
|
58 | if (data.params_json) {
|
59 | idx.params = JSON.parse(data.params_json);
|
60 | }
|
61 | if (data.source_params_json) {
|
62 | idx.sourceParams = JSON.parse(data.source_params_json);
|
63 | }
|
64 | if (data.plan_params_json) {
|
65 | idx.planParams = JSON.parse(data.plan_params_json);
|
66 | }
|
67 | return idx;
|
68 | }
|
69 | }
|
70 | exports.SearchIndex = SearchIndex;
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | class SearchIndexManager {
|
78 | |
79 |
|
80 |
|
81 | constructor(cluster) {
|
82 | this._cluster = cluster;
|
83 | }
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | async getIndex(indexName, options, callback) {
|
92 | if (options instanceof Function) {
|
93 | callback = arguments[1];
|
94 | options = undefined;
|
95 | }
|
96 | if (!options) {
|
97 | options = {};
|
98 | }
|
99 | const timeout = options.timeout || this._cluster.managementTimeout;
|
100 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
101 | this._cluster.conn.managementSearchIndexGet({
|
102 | index_name: indexName,
|
103 | timeout: timeout,
|
104 | }, (cppErr, resp) => {
|
105 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
106 | if (err) {
|
107 | return wrapCallback(err, null);
|
108 | }
|
109 | const index = SearchIndex._fromCppData(resp.index);
|
110 | wrapCallback(null, index);
|
111 | });
|
112 | }, callback);
|
113 | }
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | async getAllIndexes(options, callback) {
|
121 | if (options instanceof Function) {
|
122 | callback = arguments[0];
|
123 | options = undefined;
|
124 | }
|
125 | if (!options) {
|
126 | options = {};
|
127 | }
|
128 | const timeout = options.timeout || this._cluster.managementTimeout;
|
129 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
130 | this._cluster.conn.managementSearchIndexGetAll({
|
131 | timeout: timeout,
|
132 | }, (cppErr, resp) => {
|
133 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
134 | if (err) {
|
135 | return wrapCallback(err, null);
|
136 | }
|
137 | const indexes = resp.indexes.map((indexData) => SearchIndex._fromCppData(indexData));
|
138 | wrapCallback(null, indexes);
|
139 | });
|
140 | }, callback);
|
141 | }
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | async upsertIndex(indexDefinition, options, callback) {
|
150 | if (options instanceof Function) {
|
151 | callback = arguments[1];
|
152 | options = undefined;
|
153 | }
|
154 | if (!options) {
|
155 | options = {};
|
156 | }
|
157 | const timeout = options.timeout || this._cluster.managementTimeout;
|
158 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
159 | this._cluster.conn.managementSearchIndexUpsert({
|
160 | index: SearchIndex._toCppData(indexDefinition),
|
161 | timeout: timeout,
|
162 | }, (cppErr) => {
|
163 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
164 | if (err) {
|
165 | return wrapCallback(err, null);
|
166 | }
|
167 | wrapCallback(err);
|
168 | });
|
169 | }, callback);
|
170 | }
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | async dropIndex(indexName, options, callback) {
|
179 | if (options instanceof Function) {
|
180 | callback = arguments[1];
|
181 | options = undefined;
|
182 | }
|
183 | if (!options) {
|
184 | options = {};
|
185 | }
|
186 | const timeout = options.timeout || this._cluster.managementTimeout;
|
187 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
188 | this._cluster.conn.managementSearchIndexDrop({
|
189 | index_name: indexName,
|
190 | timeout: timeout,
|
191 | }, (cppErr) => {
|
192 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
193 | if (err) {
|
194 | return wrapCallback(err, null);
|
195 | }
|
196 | wrapCallback(err);
|
197 | });
|
198 | }, callback);
|
199 | }
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | async getIndexedDocumentsCount(indexName, options, callback) {
|
208 | if (options instanceof Function) {
|
209 | callback = arguments[1];
|
210 | options = undefined;
|
211 | }
|
212 | if (!options) {
|
213 | options = {};
|
214 | }
|
215 | const timeout = options.timeout || this._cluster.managementTimeout;
|
216 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
217 | this._cluster.conn.managementSearchIndexGetDocumentsCount({
|
218 | index_name: indexName,
|
219 | timeout: timeout,
|
220 | }, (cppErr, resp) => {
|
221 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
222 | if (err) {
|
223 | return wrapCallback(err, null);
|
224 | }
|
225 | wrapCallback(null, resp.count);
|
226 | });
|
227 | }, callback);
|
228 | }
|
229 | |
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | async pauseIngest(indexName, options, callback) {
|
237 | if (options instanceof Function) {
|
238 | callback = arguments[1];
|
239 | options = undefined;
|
240 | }
|
241 | if (!options) {
|
242 | options = {};
|
243 | }
|
244 | const timeout = options.timeout || this._cluster.managementTimeout;
|
245 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
246 | this._cluster.conn.managementSearchIndexControlIngest({
|
247 | index_name: indexName,
|
248 | pause: true,
|
249 | timeout: timeout,
|
250 | }, (cppErr) => {
|
251 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
252 | if (err) {
|
253 | return wrapCallback(err, null);
|
254 | }
|
255 | wrapCallback(err);
|
256 | });
|
257 | }, callback);
|
258 | }
|
259 | |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | async resumeIngest(indexName, options, callback) {
|
267 | if (options instanceof Function) {
|
268 | callback = arguments[1];
|
269 | options = undefined;
|
270 | }
|
271 | if (!options) {
|
272 | options = {};
|
273 | }
|
274 | const timeout = options.timeout || this._cluster.managementTimeout;
|
275 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
276 | this._cluster.conn.managementSearchIndexControlIngest({
|
277 | index_name: indexName,
|
278 | pause: false,
|
279 | timeout: timeout,
|
280 | }, (cppErr) => {
|
281 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
282 | if (err) {
|
283 | return wrapCallback(err, null);
|
284 | }
|
285 | wrapCallback(err);
|
286 | });
|
287 | }, callback);
|
288 | }
|
289 | |
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | async allowQuerying(indexName, options, callback) {
|
297 | if (options instanceof Function) {
|
298 | callback = arguments[1];
|
299 | options = undefined;
|
300 | }
|
301 | if (!options) {
|
302 | options = {};
|
303 | }
|
304 | const timeout = options.timeout || this._cluster.managementTimeout;
|
305 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
306 | this._cluster.conn.managementSearchIndexControlQuery({
|
307 | index_name: indexName,
|
308 | allow: true,
|
309 | timeout: timeout,
|
310 | }, (cppErr) => {
|
311 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
312 | if (err) {
|
313 | return wrapCallback(err, null);
|
314 | }
|
315 | wrapCallback(err);
|
316 | });
|
317 | }, callback);
|
318 | }
|
319 | |
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 | async disallowQuerying(indexName, options, callback) {
|
327 | if (options instanceof Function) {
|
328 | callback = arguments[1];
|
329 | options = undefined;
|
330 | }
|
331 | if (!options) {
|
332 | options = {};
|
333 | }
|
334 | const timeout = options.timeout || this._cluster.managementTimeout;
|
335 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
336 | this._cluster.conn.managementSearchIndexControlQuery({
|
337 | index_name: indexName,
|
338 | allow: false,
|
339 | timeout: timeout,
|
340 | }, (cppErr) => {
|
341 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
342 | if (err) {
|
343 | return wrapCallback(err, null);
|
344 | }
|
345 | wrapCallback(err);
|
346 | });
|
347 | }, callback);
|
348 | }
|
349 | |
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | async freezePlan(indexName, options, callback) {
|
357 | if (options instanceof Function) {
|
358 | callback = arguments[1];
|
359 | options = undefined;
|
360 | }
|
361 | if (!options) {
|
362 | options = {};
|
363 | }
|
364 | const timeout = options.timeout || this._cluster.managementTimeout;
|
365 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
366 | this._cluster.conn.managementSearchIndexControlPlanFreeze({
|
367 | index_name: indexName,
|
368 | freeze: true,
|
369 | timeout: timeout,
|
370 | }, (cppErr) => {
|
371 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
372 | if (err) {
|
373 | return wrapCallback(err, null);
|
374 | }
|
375 | wrapCallback(err);
|
376 | });
|
377 | }, callback);
|
378 | }
|
379 | |
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | async unfreezePlan(indexName, options, callback) {
|
387 | if (options instanceof Function) {
|
388 | callback = arguments[1];
|
389 | options = undefined;
|
390 | }
|
391 | if (!options) {
|
392 | options = {};
|
393 | }
|
394 | const timeout = options.timeout || this._cluster.managementTimeout;
|
395 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
396 | this._cluster.conn.managementSearchIndexControlPlanFreeze({
|
397 | index_name: indexName,
|
398 | freeze: false,
|
399 | timeout: timeout,
|
400 | }, (cppErr) => {
|
401 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
402 | if (err) {
|
403 | return wrapCallback(err, null);
|
404 | }
|
405 | wrapCallback(err);
|
406 | });
|
407 | }, callback);
|
408 | }
|
409 | |
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | async analyzeDocument(indexName, document, options, callback) {
|
418 | if (options instanceof Function) {
|
419 | callback = arguments[2];
|
420 | options = undefined;
|
421 | }
|
422 | if (!options) {
|
423 | options = {};
|
424 | }
|
425 | const timeout = options.timeout || this._cluster.managementTimeout;
|
426 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
427 | this._cluster.conn.managementSearchIndexAnalyzeDocument({
|
428 | index_name: indexName,
|
429 | encoded_document: JSON.stringify(document),
|
430 | timeout: timeout,
|
431 | }, (cppErr, resp) => {
|
432 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
433 | if (err) {
|
434 | return wrapCallback(err, null);
|
435 | }
|
436 | const result = JSON.parse(resp.analysis);
|
437 | wrapCallback(result, null);
|
438 | });
|
439 | }, callback);
|
440 | }
|
441 | }
|
442 | exports.SearchIndexManager = SearchIndexManager;
|