Reputation: 11
I am looking for an example on how to call discovery.query in node.js. More specifically, an example in which multiple query options are used.
The documentation mentions "query string", but I don't know how to translate that in an actual call in node.js.
Thanks in advance, Arie
Upvotes: 1
Views: 1561
Reputation: 5330
You can see the line #652 from Documentation Node SDK - Watson Developer Cloud, according to SDK doc found the method receives a parameter
object {}
Then, see one example to use query string with Discovery with Nodejs.
require('dotenv').config({ silent: true });
//for access variables .env process.env.nameVariable
var DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
var discovery = new DiscoveryV1({
username: process.env.DISCOVERY_USERNAME,
password: process.env.DISCOVERY_PASSWORD,
version_date: '2017-09-01'
});
var params = {
'query': "Sayuri",
'environment_id': process.env.enviroment_id,
'collection_id': process.env.collection_id,
'configuration_id': process.env.configuration_id,
//'passages': true, //if you want to enable passages
return: 'text, title'
//'highlight': true //if you want to enable highlight
}
discovery.query(params, (error, results) => {
if (error) {
next(error);
} else {
console.log(results); //your query results
}
});
Upvotes: 2