Marklogic: what are field range query and path range query cts functions using xquery

Viewed 69

I have been following the documentation to understand cts:field-range-query and cts:path-range-query. These are the links i used to understand. https://docs.marklogic.com/cts:field-range-query https://docs.marklogic.com/cts:path-range-query

In cts:path-range-query, i didnt understand the output. How do you compare a string with < or >?

cts:search(doc(),cts:path-range-query("/name/fname",">","Jim"),"filtered")
 =>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>John</fname><mname>Rob</mname><lname>Goldings</lname></name>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>Ooi</fname><mname>Ben</mname><lname>Fu</lname></name>

In cts:field-range-query, here aswell i didnt get the output.

ts:search(doc(),cts:field-range-query("aname",">","Jim Kurla"));

(:
  returns the following:
<?xml version="1.0" encoding="UTF-8"?>
<name>
  <fname>John</fname>
  <mname>Rob</mname>
  <lname>Goldings</lname>
</name>
<?xml version="1.0" encoding="UTF-8"?>
<name>
  <fname>Ooi</fname>
  <mname>Ben</mname>
  <lname>Fu</lname>
</name>
:)

Sorry, if it is silly but i have been trying to understand this little thing since several days but somehow i don't get it. Really appreciate the help

1 Answers

String comparison is based on alphanumeric comparison. It actually depends on the collation, but the default is based on Unicode (UCA Root Collation with case and diacritic sensitivity). A comes before B, but a comes after B, and also alpha comes after Zeta. More confusingly, 10 comes before 2 as well.

In your examples the path query only looks at fname where Jim comes before both John and Ooi.

The second example is likely a field with multiple paths, including fname, mname, and lname. The > satisfies if there is any name value in the document that is larger than Jim. Goldings, Ben, and Fu come before Jim alphabetically, but there are other names like John and Ooi that come after. So that returns both those values as well.

It is more fun to repeat the queries with Lee. The path query will then return 1 result only (the second), but the field is likely still returning both.

Related