如何基于集合计数并使用XQuery进行多元素字查询?

时间:2018-06-13 18:36:29

标签: xquery marklogic marklogic-8

尝试根据不同的过滤器和一个集合计算汽车数量。即使我们看到多辆汽车满足要求,查询也会返回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
    } 

1 个答案:

答案 0 :(得分:6)

当您需要使用cts:json-property-value-query("propertyName", json:null()) 时,您正在使用byAPI Documentation

要测试null,我相信你应该使用:

merge