1

I have recently started working on MarkLogic 10 Database

What I need to do is find the documents who have id like

wew35r-ui856-iiu

When I query like this

cts:element-value-match(xs:Qname("id"),".*\-.*")

I get 0 results

but when I do

fn:matches("wew35r-ui856-iiu",".*\-.*")
It return true

And surprisingly when I do

cts:element-value-match(xs:Qname("id"),"*")

I get whole list which includes wew35r-ui856-iiu as well.

I had looked into the documentation and all but was not able to make it work.

Sunny
  • 2,074
  • 4
  • 24
  • 33

1 Answers1

3

Full regex patterns are not supported for cts:element-value-match, only wildcard patterns.

To use a wildcard pattern to look for values that contain a dash -:

cts:element-value-match(xs:QName("id"),"*-*")

And then if you needed, you could filter those results with a more specific regex in a predicate filter:

cts:element-value-match(xs:QName("id"),"*-*")[matches(., "(\w+-\w+){2}")]
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • 3
    A footnote on this useful explanation: `cts:element-value-match()` matches documents based on a query over indexes where `fn:matches()` filters by inspecting documents in memory. For good performance at scale, it's best to do as much querying on indexes and as little filtering in memory as possible. – ehennum Aug 25 '20 at 15:09