Warm tip: This article is reproduced from stackoverflow.com, please click
marklogic marklogic-9

How to use fn:starts-with() and fn:ends-with() with cts:uris()

发布于 2020-05-09 18:51:41

My Requirement is, I want to return document URI only if path range index value is starts-with or ends-with some word.

As Per MarkLogic documentation I can only use ">, <, <=, >=, =, !=" to compare path range index value but in my requirement I want to use fn:starts-with() or fn:ends-with().

Is there any way to satisfy this requirement?

Questioner
Shivling Bhandare
Viewed
78
Mads Hansen 2020-02-25 22:14

You could use cts:value-match() with leading and trailing wildcards to find all of the values that start-with and end-with the value.

Then use cts:path-range-query() with those values in a call to 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))