node.js - 为什么使用 cts 搜索数组与使用 node api 搜索数组不同?

标签 node.js marklogic

我有一个类似这个问题的问题: Marklogic (Nodejs API) - Search documents that match 2 (or more) conditions in object array attribute

我有以下文件:

{
  "address": [
    { "type": "mailing",
      "street": "1001 Main Street",
      "city": "Springfield",
      "state": "MO"
    },
    { "type": "location",
      "street": "989 First Street",
      "city": "Johnstone",
      "state": "WY"
    }
  ]
}

当我在查询控制台中运行以下代码时,它没有正确返回文档:

'use strict';

const queryText = 
  cts.jsonPropertyScopeQuery("address", cts.andQuery([
    cts.jsonPropertyWordQuery("city", "Johnstone"),
    cts.jsonPropertyWordQuery("state", "MO")
  ]));

cts.search(queryText);

当我在 Node.js 中运行这段代码时,它确实返回了文档,因为它在评估时似乎组合了所有数组 Node 。

const queryText =
  qb.scope(qb.property("address"), qb.and(
    qb.word("city","Johnstone"),
    qb.word("state","MO")
  ));

const query = qb.where(queryText);

有没有一种方法可以使用 Node API 获得 cts 功能?与在服务器端 javascript 查询上使用调用相比,我更愿意使用 Node API。

最佳答案

默认情况下,SJS 搜索运行过滤,这将删除任何误报结果。您可以通过向 SJS 搜索添加显式选项来切换该行为:

cts.search(queryText, "unfiltered");

默认情况下,运行 Node.js 查询 unfiltered ,这意味着您可能会遇到假阳性结果。

为了让您的 Node.js 搜索运行过滤,将过滤搜索选项添加到您的查询:

const query = qb.where(queryText)
  .withOptions({search:['filtered']});

关于node.js - 为什么使用 cts 搜索数组与使用 node api 搜索数组不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52563833/

相关文章:

gradle - Marklogic Spring Boot - 安装 Rest Endpoint

exception - Marklogic 插入包含 &fm=1 的简单 url,出现 "invalid entity reference"异常错误

java - MarkLogic 通配符搜索 - 控制台与 Java API

node.js - 通过nodemailer发送带有一些图像的html

node.js - Zombie.js "assert is not defined"多次访问?

marklogic - 通过脚本关闭主机

xpath - 有没有快速的方法来找到与 cts :element-value-match()? 匹配的父节点

node.js - 使用 WebStorm 设置 MEAN.io

Node.js ftp put方法写的是要上传到ftp服务器的文件名,不是实际文件

node.js - Azure Linux Web 服务器没有响应我的 Docker 容器