Skip to content

Commit 4697555

Browse files
committed
Correct Discovery Implementation of passages
1 parent 182ca0e commit 4697555

6 files changed

Lines changed: 48 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.6.8
11+
- Move all Discovery calls to latest API version - 2017-11-07
12+
- Updated calls to deprecated discovery methods addJsonDocument and getCollections
13+
- Correct implemetation of passages related options
14+
1015
### New in version 0.6.7
1116
- Enable Opt-out option for Conversation Node.
1217
- Implement time out option for response from Conversation Node.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -10,7 +10,7 @@
1010
"temp": "^0.8.3",
1111
"qs": "6.x",
1212
"image-type": "^2.0.2",
13-
"watson-developer-cloud": "^3.2.1",
13+
"watson-developer-cloud": "^3.3.0",
1414
"kuromoji": "^0.1.1",
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",

services/discovery/discovery-utils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ DiscoveryUtils.prototype = {
7171
return params;
7272
},
7373

74+
buildParamsForPassages: function (me, msg, config, params) {
75+
let passagesFound = false;
76+
77+
// Allow the passages parameters to be passed in two ways
78+
// 1. As the API is expecting
79+
['passages.fields', 'passages.count', 'passages.characters'
80+
].forEach(function(f) {
81+
params = me.buildParamsFor(msg, config, params, f);
82+
passagesFound = true;
83+
});
84+
85+
// 2. As anyone misreading the documentation might do it.
86+
if (msg.discoveryparams && msg.discoveryparams.passages) {
87+
passagesFound = true;
88+
['fields', 'count', 'characters'
89+
].forEach(function(f) {
90+
if (msg.discoveryparams.passages[f]) {
91+
params['passages.' + f] = msg.discoveryparams.passages[f];
92+
}
93+
});
94+
}
95+
96+
if (passagesFound) {
97+
params.passages = true;
98+
}
99+
100+
return params;
101+
},
102+
74103
buildParamsFromConfig: function(config, params, field) {
75104
if (config[field]) {
76105
params[field] = config[field];
@@ -101,6 +130,8 @@ DiscoveryUtils.prototype = {
101130
params = me.buildParamsFor(msg, config, params, f);
102131
});
103132

133+
params = me.buildParamsForPassages(me, msg, config, params);
134+
104135
['count', 'filter', 'aggregation', 'return'].forEach(function(f) {
105136
params = me.buildParamsFromConfig(config, params, f);
106137
});

services/discovery/v1-document-loader.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module.exports = function (RED) {
130130
serviceSettings = {
131131
username: username,
132132
password: password,
133-
version_date: '2017-09-01',
133+
version_date: '2017-11-07',
134134
headers: {
135135
'User-Agent': pkg.name + '-' + pkg.version
136136
}
@@ -141,12 +141,13 @@ module.exports = function (RED) {
141141
}
142142

143143
discovery = new DiscoveryV1(serviceSettings);
144-
145-
if ('.json' === suffix) {
146-
method = 'addJsonDocument';
147-
} else {
148-
method = 'addDocument';
149-
}
144+
// addJsonDocument is deprecated
145+
//if ('.json' === suffix) {
146+
// method = 'addJsonDocument';
147+
//} else {
148+
// method = 'addDocument';
149+
//}
150+
method = 'addDocument';
150151

151152
discovery[method](params, function (err, response) {
152153
if (err) {

services/discovery/v1-query-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = function(RED) {
7070
}
7171
});
7272

73-
discovery.getCollections({
73+
discovery.listCollections({
7474
environment_id: req.query.environment_id
7575
},
7676
function(err, response) {

services/discovery/v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ module.exports = function (RED) {
251251
serviceSettings = {
252252
username: username,
253253
password: password,
254-
version_date: '2017-09-01',
254+
version_date: '2017-11-07',
255255
headers: {
256256
'User-Agent': pkg.name + '-' + pkg.version
257257
}

0 commit comments

Comments
 (0)