forked from watson-developer-cloud/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2.ts
3668 lines (3355 loc) · 135 KB
/
v2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* (C) Copyright IBM Corp. 2019, 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as extend from 'extend';
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
import { Authenticator, BaseService, getAuthenticatorFromEnvironment, getMissingParams, UserOptions } from 'ibm-cloud-sdk-core';
import { getSdkHeaders } from '../lib/common';
/**
* IBM Watson™ Discovery is a cognitive search and content analytics engine that you can add to applications to
* identify patterns, trends and actionable insights to drive better decision-making. Securely unify structured and
* unstructured data with pre-enriched content, and use a simplified query language to eliminate the need for manual
* filtering of results.
*/
class DiscoveryV2 extends BaseService {
static DEFAULT_SERVICE_URL: string = 'https://api.us-south.discovery.watson.cloud.ibm.com';
static DEFAULT_SERVICE_NAME: string = 'discovery';
/**
* Construct a DiscoveryV2 object.
*
* @param {Object} options - Options for the service.
* @param {string} options.version - The API version date to use with the service, in "YYYY-MM-DD" format. Whenever
* the API is changed in a backwards incompatible way, a new minor version of the API is released. The service uses
* the API version for the date you specify, or the most recent version before that date. Note that you should not
* programmatically specify the current date at runtime, in case the API has been updated since your application's
* release. Instead, specify a version date that is compatible with your application, and don't change it until your
* application is ready for a later version.
* @param {string} [options.serviceUrl] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net'). The base url may differ between IBM Cloud regions.
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
* @constructor
* @returns {DiscoveryV2}
* @throws {Error}
*/
constructor(options: UserOptions) {
if (!options.serviceName) {
options.serviceName = DiscoveryV2.DEFAULT_SERVICE_NAME;
}
// If the caller didn't supply an authenticator, construct one from external configuration.
if (!options.authenticator) {
options.authenticator = getAuthenticatorFromEnvironment(options.serviceName);
}
super(options);
this.configureService(options.serviceName);
if (options.serviceUrl) {
this.setServiceUrl(options.serviceUrl);
}
// check if 'version' was provided
if (typeof this.baseOptions.version === 'undefined') {
throw new Error('Argument error: version was not specified');
}
this.baseOptions.qs.version = options.version;
}
/*************************
* collections
************************/
/**
* List collections.
*
* Lists existing collections for the specified project.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListCollectionsResponse>>}
*/
public listCollections(params: DiscoveryV2.ListCollectionsParams, callback?: DiscoveryV2.Callback<DiscoveryV2.ListCollectionsResponse>): Promise<DiscoveryV2.Response<DiscoveryV2.ListCollectionsResponse>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listCollections');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections',
method: 'GET',
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Create a collection.
*
* Create a new collection in the specified project.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.name - The name of the collection.
* @param {string} [params.description] - A description of the collection.
* @param {string} [params.language] - The language of the collection.
* @param {CollectionEnrichment[]} [params.enrichments] - An array of enrichments that are applied to this collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
public createCollection(params: DiscoveryV2.CreateCollectionParams, callback?: DiscoveryV2.Callback<DiscoveryV2.CollectionDetails>): Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'name'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'enrichments': _params.enrichments
};
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'createCollection');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections',
method: 'POST',
body,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Get collection.
*
* Get details about the specified collection.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.collectionId - The ID of the collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
public getCollection(params: DiscoveryV2.GetCollectionParams, callback?: DiscoveryV2.Callback<DiscoveryV2.CollectionDetails>): Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'collectionId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getCollection');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'GET',
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Update a collection.
*
* Updates the specified collection's name, description, and enrichments.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.collectionId - The ID of the collection.
* @param {string} [params.name] - The name of the collection.
* @param {string} [params.description] - A description of the collection.
* @param {CollectionEnrichment[]} [params.enrichments] - An array of enrichments that are applied to this collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
public updateCollection(params: DiscoveryV2.UpdateCollectionParams, callback?: DiscoveryV2.Callback<DiscoveryV2.CollectionDetails>): Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'collectionId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const body = {
'name': _params.name,
'description': _params.description,
'enrichments': _params.enrichments
};
const path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'updateCollection');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'POST',
body,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Delete a collection.
*
* Deletes the specified collection from the project. All documents stored in the specified collection and not shared
* is also deleted.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.collectionId - The ID of the collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.Empty>>}
*/
public deleteCollection(params: DiscoveryV2.DeleteCollectionParams, callback?: DiscoveryV2.Callback<DiscoveryV2.Empty>): Promise<DiscoveryV2.Response<DiscoveryV2.Empty>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'collectionId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteCollection');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'DELETE',
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/*************************
* queries
************************/
/**
* Query a project.
*
* By using this method, you can construct queries. For details, see the [Discovery
* documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-query-concepts). The default query
* parameters are defined by the settings for this project, see the [Discovery
* documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-project-defaults) for an overview of
* the standard default settings, and see [the Projects API documentation](#create-project) for details about how to
* set custom default query settings.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string[]} [params.collectionIds] - A comma-separated list of collection IDs to be queried against.
* @param {string} [params.filter] - A cacheable query that excludes documents that don't mention the query content.
* Filter searches are better for metadata-type searches and for assessing the concepts in the data set.
* @param {string} [params.query] - A query search returns all documents in your data set with full enrichments and
* full text, but with the most relevant documents listed first. Use a query search when you want to find the most
* relevant search results.
* @param {string} [params.naturalLanguageQuery] - A natural language query that returns relevant documents by
* utilizing training data and natural language understanding.
* @param {string} [params.aggregation] - An aggregation search that returns an exact answer by combining query search
* with filters. Useful for applications to build lists, tables, and time series. For a full list of possible
* aggregations, see the Query reference.
* @param {number} [params.count] - Number of results to return.
* @param {string[]} [params._return] - A list of the fields in the document hierarchy to return. If this parameter
* not specified, then all top-level fields are returned.
* @param {number} [params.offset] - The number of query results to skip at the beginning. For example, if the total
* number of results that are returned is 10 and the offset is 8, it returns the last two results.
* @param {string} [params.sort] - A comma-separated list of fields in the document to sort on. You can optionally
* specify a sort direction by prefixing the field with `-` for descending or `+` for ascending. Ascending is the
* default sort direction if no prefix is specified. This parameter cannot be used in the same query as the **bias**
* parameter.
* @param {boolean} [params.highlight] - When `true`, a highlight field is returned for each result which contains the
* fields which match the query with `<em></em>` tags around the matching query terms.
* @param {boolean} [params.spellingSuggestions] - When `true` and the **natural_language_query** parameter is used,
* the **natural_language_query** parameter is spell checked. The most likely correction is returned in the
* **suggested_query** field of the response (if one exists).
* @param {QueryLargeTableResults} [params.tableResults] - Configuration for table retrieval.
* @param {QueryLargeSuggestedRefinements} [params.suggestedRefinements] - Configuration for suggested refinements.
* @param {QueryLargePassages} [params.passages] - Configuration for passage retrieval.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.QueryResponse>>}
*/
public query(params: DiscoveryV2.QueryParams, callback?: DiscoveryV2.Callback<DiscoveryV2.QueryResponse>): Promise<DiscoveryV2.Response<DiscoveryV2.QueryResponse>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const body = {
'collection_ids': _params.collectionIds,
'filter': _params.filter,
'query': _params.query,
'natural_language_query': _params.naturalLanguageQuery,
'aggregation': _params.aggregation,
'count': _params.count,
'return': _params._return,
'offset': _params.offset,
'sort': _params.sort,
'highlight': _params.highlight,
'spelling_suggestions': _params.spellingSuggestions,
'table_results': _params.tableResults,
'suggested_refinements': _params.suggestedRefinements,
'passages': _params.passages
};
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'query');
const parameters = {
options: {
url: '/v2/projects/{project_id}/query',
method: 'POST',
body,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Get Autocomplete Suggestions.
*
* Returns completion query suggestions for the specified prefix.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.prefix - The prefix to use for autocompletion. For example, the prefix `Ho` could
* autocomplete to `Hot`, `Housing`, or `How do I upgrade`. Possible completions are.
* @param {string[]} [params.collectionIds] - Comma separated list of the collection IDs. If this parameter is not
* specified, all collections in the project are used.
* @param {string} [params.field] - The field in the result documents that autocompletion suggestions are identified
* from.
* @param {number} [params.count] - The number of autocompletion suggestions to return.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.Completions>>}
*/
public getAutocompletion(params: DiscoveryV2.GetAutocompletionParams, callback?: DiscoveryV2.Callback<DiscoveryV2.Completions>): Promise<DiscoveryV2.Response<DiscoveryV2.Completions>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'prefix'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const query = {
'prefix': _params.prefix,
'collection_ids': _params.collectionIds,
'field': _params.field,
'count': _params.count
};
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getAutocompletion');
const parameters = {
options: {
url: '/v2/projects/{project_id}/autocompletion',
method: 'GET',
qs: query,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Query system notices.
*
* Queries for notices (errors or warnings) that might have been generated by the system. Notices are generated when
* ingesting documents and performing relevance training.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} [params.filter] - A cacheable query that excludes documents that don't mention the query content.
* Filter searches are better for metadata-type searches and for assessing the concepts in the data set.
* @param {string} [params.query] - A query search returns all documents in your data set with full enrichments and
* full text, but with the most relevant documents listed first.
* @param {string} [params.naturalLanguageQuery] - A natural language query that returns relevant documents by
* utilizing training data and natural language understanding.
* @param {number} [params.count] - Number of results to return. The maximum for the **count** and **offset** values
* together in any one query is **10000**.
* @param {number} [params.offset] - The number of query results to skip at the beginning. For example, if the total
* number of results that are returned is 10 and the offset is 8, it returns the last two results. The maximum for the
* **count** and **offset** values together in any one query is **10000**.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.QueryNoticesResponse>>}
*/
public queryNotices(params: DiscoveryV2.QueryNoticesParams, callback?: DiscoveryV2.Callback<DiscoveryV2.QueryNoticesResponse>): Promise<DiscoveryV2.Response<DiscoveryV2.QueryNoticesResponse>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const query = {
'filter': _params.filter,
'query': _params.query,
'natural_language_query': _params.naturalLanguageQuery,
'count': _params.count,
'offset': _params.offset
};
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'queryNotices');
const parameters = {
options: {
url: '/v2/projects/{project_id}/notices',
method: 'GET',
qs: query,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* List fields.
*
* Gets a list of the unique fields (and their types) stored in the the specified collections.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string[]} [params.collectionIds] - Comma separated list of the collection IDs. If this parameter is not
* specified, all collections in the project are used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListFieldsResponse>>}
*/
public listFields(params: DiscoveryV2.ListFieldsParams, callback?: DiscoveryV2.Callback<DiscoveryV2.ListFieldsResponse>): Promise<DiscoveryV2.Response<DiscoveryV2.ListFieldsResponse>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const query = {
'collection_ids': _params.collectionIds
};
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listFields');
const parameters = {
options: {
url: '/v2/projects/{project_id}/fields',
method: 'GET',
qs: query,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/*************************
* componentSettings
************************/
/**
* List component settings.
*
* Returns default configuration settings for components.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ComponentSettingsResponse>>}
*/
public getComponentSettings(params: DiscoveryV2.GetComponentSettingsParams, callback?: DiscoveryV2.Callback<DiscoveryV2.ComponentSettingsResponse>): Promise<DiscoveryV2.Response<DiscoveryV2.ComponentSettingsResponse>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const path = {
'project_id': _params.projectId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getComponentSettings');
const parameters = {
options: {
url: '/v2/projects/{project_id}/component_settings',
method: 'GET',
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/*************************
* documents
************************/
/**
* Add a document.
*
* Add a document to a collection with optional metadata.
*
* Returns immediately after the system has accepted the document for processing.
*
* * The user must provide document content, metadata, or both. If the request is missing both document content and
* metadata, it is rejected.
*
* * The user can set the **Content-Type** parameter on the **file** part to indicate the media type of the
* document. If the **Content-Type** parameter is missing or is one of the generic media types (for example,
* `application/octet-stream`), then the service attempts to automatically detect the document's media type.
*
* * The following field names are reserved and will be filtered out if present after normalization: `id`, `score`,
* `highlight`, and any field with the prefix of: `_`, `+`, or `-`
*
* * Fields with empty name values after normalization are filtered out before indexing.
*
* * Fields containing the following characters after normalization are filtered out before indexing: `#` and `,`
*
* If the document is uploaded to a collection that has it's data shared with another collection, the
* **X-Watson-Discovery-Force** header must be set to `true`.
*
* **Note:** Documents can be added with a specific **document_id** by using the
* **_/v2/projects/{project_id}/collections/{collection_id}/documents** method.
*
* **Note:** This operation only works on collections created to accept direct file uploads. It cannot be used to
* modify a collection that connects to an external source such as Microsoft SharePoint.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.collectionId - The ID of the collection.
* @param {NodeJS.ReadableStream|Buffer} [params.file] - The content of the document to ingest. The maximum supported
* file size when adding a file to a collection is 50 megabytes, the maximum supported file size when testing a
* configuration is 1 megabyte. Files larger than the supported size are rejected.
* @param {string} [params.filename] - The filename for file.
* @param {string} [params.fileContentType] - The content type of file.
* @param {string} [params.metadata] - The maximum supported metadata file size is 1 MB. Metadata parts larger than 1
* MB are rejected.
*
*
* Example: ``` {
* "Creator": "Johnny Appleseed",
* "Subject": "Apples"
* } ```.
* @param {boolean} [params.xWatsonDiscoveryForce] - When `true`, the uploaded document is added to the collection
* even if the data for that collection is shared with other collections.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.DocumentAccepted>>}
*/
public addDocument(params: DiscoveryV2.AddDocumentParams, callback?: DiscoveryV2.Callback<DiscoveryV2.DocumentAccepted>): Promise<DiscoveryV2.Response<DiscoveryV2.DocumentAccepted>> {
const _params = extend({}, params);
const _callback = callback;
const requiredParams = ['projectId', 'collectionId'];
return new Promise((resolve, reject) => {
const missingParams = getMissingParams(_params, requiredParams);
if (missingParams) {
if (_callback) {
_callback(missingParams);
return resolve();
}
return reject(missingParams);
}
const formData = {
'file': {
data: _params.file,
filename: _params.filename,
contentType: _params.fileContentType
},
'metadata': _params.metadata
};
const path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId
};
const sdkHeaders = getSdkHeaders(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'addDocument');
const parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents',
method: 'POST',
path,
formData
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'X-Watson-Discovery-Force': _params.xWatsonDiscoveryForce
}, _params.headers),
}),
};
return this.createRequest(parameters).then(
res => {
if (_callback) {
_callback(null, res);
}
return resolve(res);
},
err => {
if (_callback) {
_callback(err)
return resolve();
}
return reject(err);
}
);
});
};
/**
* Update a document.
*
* Replace an existing document or add a document with a specified **document_id**. Starts ingesting a document with
* optional metadata.
*
* If the document is uploaded to a collection that has it's data shared with another collection, the
* **X-Watson-Discovery-Force** header must be set to `true`.
*
* **Note:** When uploading a new document with this method it automatically replaces any document stored with the
* same **document_id** if it exists.
*
* **Note:** This operation only works on collections created to accept direct file uploads. It cannot be used to
* modify a collection that connects to an external source such as Microsoft SharePoint.
*
* **Note:** If an uploaded document is segmented, all segments will be overwritten, even if the updated version of
* the document has fewer segments.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The ID of the project. This information can be found from the deploy page of the
* Discovery administrative tooling.
* @param {string} params.collectionId - The ID of the collection.
* @param {string} params.documentId - The ID of the document.
* @param {NodeJS.ReadableStream|Buffer} [params.file] - The content of the document to ingest. The maximum supported
* file size when adding a file to a collection is 50 megabytes, the maximum supported file size when testing a
* configuration is 1 megabyte. Files larger than the supported size are rejected.
* @param {string} [params.filename] - The filename for file.
* @param {string} [params.fileContentType] - The content type of file.
* @param {string} [params.metadata] - The maximum supported metadata file size is 1 MB. Metadata parts larger than 1
* MB are rejected.