简体   繁体   中英

Watson Discovery: Example using query options in node.js

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

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
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM