Search code examples
marklogic

cts:triple-range-query with triple in document propties


I would like to to execute a cts:triple-range-query as illustrated in the example section on https://docs.marklogic.com/cts:triple-range-query. However, I put the triple in the document properties.

enter image description here

Unfortunately, the following query does not return the document.

xquery version "1.0-ml";

let $query := cts:triple-range-query(
  sem:iri("http://example.com/Mark"),
  sem:iri("http://example.com/ns/person#age"),
  50,
  "<"
)
return cts:search(fn:doc(), $query)

How can I make the query work with triples stored in the document properties?


Solution

  • Try encapsulating your query in cts:properties-fragment-query like so:

    return cts:search(fn:doc(), cts:properties-fragment-query($query))
    

    You will probably achieve more performant results as you scale out by instead using the envelope or sidecar (2nd document with deterministic URI) design patterns.