gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:50:28 27 4
gpt4 key购买 nike

我有一个类似这个问题的问题: 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com