【问题标题】:IBM Bluemix Discovery - query parameterIBM Bluemix Discovery - 查询参数
【发布时间】:2017-06-28 15:29:54
【问题描述】:

我在我的 bluemix 帐户上创建了一项发现服务。我想从 nodejs 应用程序中查询我的文档。

我用一些聚合构建了一个查询,使用 bluemix 在线工具对其进行了测试,并且运行良好。

现在,当我从我的代码中查询集合时,无论我的参数是什么,我总是会收到包含丰富文本等的所有文档。我想我错过了如何将查询属性发送到服务(如过滤器和聚合)。

这是我的代码:

var queryParams = {
  query:'CHLOE RICHARDS',
  return:'title',
  count:1,
  aggregations:'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)'
};

discovery.query({environment_id:that.environment_id, collection_id:that.collection_id, query_options:queryParams }, function(error, data) {
  if(error){
    console.error(error);
    reject(error);
  }
  else{
    console.log(JSON.stringify(data, null, 2));
    resolve(data.matching_results);
  }
});

结果总是:

{
  "matching_results": 28,
  "results": [
    {
      "id": "fe5e2a38e6cccfbd97dbdd0c33c9c8fd",
      "score": 1,
      "extracted_metadata": {
        "publicationdate": "2016-01-05",
        "sha1": "28434b0a7e2a94dd62cabe9b5a82e98766584dd412",
        "author": "Richardson, Heather S",
        "filename": "whatever.docx",
        "file_type": "word",
        "title": "no title"
      },
      "text": "......

独立于query_option参数的值。你能帮帮我吗?

编辑

我使用了query:"text:CHLOE RICHARDS" 而不是query_options:queryParams,它运行良好。现在我的问题仍然是找到正确的参数格式来添加我想要的聚合

编辑 2

所以我更仔细地查看了IBM's example on Github,现在参数的格式是这样的:

const queryParams = {
  count: 5,
  return: 'title,enrichedTitle.text',
  query: '"CHLOE RICHARDS"',
  aggregations: [ 'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)' ],
  environment_id: '1111111111',
  collection_id: '11111111111'
};

如果我只使用查询属性,效果会很好。现在,如果我只使用 aggregations 一个,所有文档都会作为结果返回(这是可以理解的),但我没有聚合部分,所以我无法访问文档中的专有名称列表。

【问题讨论】:

    标签: node.js ibm-cloud watson-discovery


    【解决方案1】:

    您的查询看起来不正确。如果您将使用query,那么您将需要构建一个查询搜索,例如text:"CHLOE RICHARDS"

    如果你想执行自然语言查询,那么你应该设置参数natural_language_query

    【讨论】:

    • 您好!谢谢您的回答。它看起来像。我用text:"CHLOE RICHARDS" 得到了同样的结果。如果有的话,这个请求应该只发回一份文件,而不是 28 份。
    • 另外,在watson discovey API reference中,查询选项中没有text,只有query...
    • 我想我开始明白你的意思了,看看我的问题的编辑......你将如何完成查询参数以添加聚合?
    • 您好,我已经这样做了,并且聚合部分的格式很好(我使用发现 Web 界面对其进行了测试,它给了我想要的结果)。我的问题是在我的代码中格式化查询的参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多