如何基于集合获取计数并使用 XQuery 进行多元素词查询?
How to get count based on collection and using multiple element-word-query with XQuery?
尝试根据不同的过滤器计算一个集合中的汽车数量。即使我们看到多辆汽车满足要求,查询返回计数 0。
fn:count(cts:search(fn:collection("com.cars"), cts:and-query((
cts:element-word-query(xs:QName("exteriorColor"), "red", "wildcarded" ),
cts:element-word-query(xs:QName("interiorColor"), "gray", "wildcarded" )
cts:element-word-query(xs:QName("powerSteering"), json:null(), "wildcarded" )
))))
测试数据:
{
"id":1
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":2
"carName":"Toyoto",
"exteriorColor": "blue",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":3
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": "yes"
}
{
"id":4
"carName":"Toyoto",
"exteriorColor": "white",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":5
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": null
}
当您需要使用 cts:json-property-word-query
时,您使用的是 cts:element-word-query
:https://docs.marklogic.com/cts:json-property-word-query
要测试 null,我相信你应该使用:
cts:json-property-value-query("propertyName", json:null())
尝试根据不同的过滤器计算一个集合中的汽车数量。即使我们看到多辆汽车满足要求,查询返回计数 0。
fn:count(cts:search(fn:collection("com.cars"), cts:and-query((
cts:element-word-query(xs:QName("exteriorColor"), "red", "wildcarded" ),
cts:element-word-query(xs:QName("interiorColor"), "gray", "wildcarded" )
cts:element-word-query(xs:QName("powerSteering"), json:null(), "wildcarded" )
))))
测试数据:
{
"id":1
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":2
"carName":"Toyoto",
"exteriorColor": "blue",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":3
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": "yes"
}
{
"id":4
"carName":"Toyoto",
"exteriorColor": "white",
"interiorColor": "gray",
"powerStreering": null
}
{
"id":5
"carName":"Toyoto",
"exteriorColor": "red",
"interiorColor": "gray",
"powerStreering": null
}
当您需要使用 cts:json-property-word-query
时,您使用的是 cts:element-word-query
:https://docs.marklogic.com/cts:json-property-word-query
要测试 null,我相信你应该使用:
cts:json-property-value-query("propertyName", json:null())