温馨提示:本文翻译自stackoverflow.com,查看原文请点击:marklogic - How to use fn:starts-with() and fn:ends-with() with cts:uris()
marklogic marklogic-9

marklogic - 如何在cts:uris()中使用fn:starts-with()和fn:ends-with()

发布于 2020-05-13 19:24:06

我的要求是,仅当路径范围索引值以某个单词开头或结尾时才想返回文档URI。

根据Per MarkLogic文档,我只能使用“>,<,<=,> =,=,!=”来比较路径范围索引值,但在我的要求下,我想使用fn:starts-with()或fn:ends- with()。

有什么办法可以满足这个要求?

查看更多

提问者
Shivling Bhandare
被浏览
75
Mads Hansen 2020-02-25 22:14

您可以使用cts:value-match()前导和尾随通配符来查找所有以该值开头和结尾的值。

然后cts:path-range-query()在调用中使用这些值cts:uris()

let $path := "/doc/foo";
let $word := "bar";
(: find the values that start with and end with the $word :)
let $values-starts-and-ends-with := (
  cts:value-match(cts:path-reference($path), $word||"*"), 
  cts:value-match(cts:path-reference($path), "*"||$word)
) 
(: use those values to find the URIs of docs with those values at that path :)
cts:uris("", (), cts:path-range-query($path, "=", $values-starts-and-ends-with))