Search code examples
marklogicmarklogic-8triplestore

How to return a set of MarkLogic URIs using cts:triple-range-query()?


I have a content repository where the latest versions of documents use an IsLatestVersion triple.

This is an example of a document with the isLatestVersion triple.

 Document URI: /Transaction/00000000000101000000/1.xml

 <aptp:Transaction xmlns:aptp="http://sample.com/aptp">
   <aptp:TransactionDate>2016-07-28</aptp:TransactionDate>
   <aptp:TransactionType>Principal</aptp:TransactionType>
   <aptp:Operation>Buy</aptp:Operation>
   <sem:triple name="isLatestVersion"
               xmlns:aptp="http://sample.com/aptp"
               xmlns:sem="http://marklogic.com/semantics">
     <sem:subject datatype="http://www.w3.org/2001/XMLSchema#string">
         /Transaction/00000000000101000000/1.xml
     </sem:subject>
     <sem:predicate>isLatestVersion</sem:predicate>
     <sem:object datatype="http://www.w3.org/2001/XMLSchema#boolean">true</sem:object>
   </sem:triple>
 </aptp:Transaction>

I'd like the following code snippet to return the sequence of latest version uris. It currently returns an empty set.

import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";

let $uris :=
  (
    "/Transaction/00000000000101000000/1.xml",
    "/Transaction/00000000000101000001/1.xml",
    "/Transaction/111111/1.xml"
  )

let $query := cts:triple-range-query($uris, "isLatestVersion", fn:true())

return
  cts:uris("", (), $query)

Am I missing something obvious?


Solution

  • A few thoughts:

    • Consider omitting $uris in the cts:triple-range-query. You can pass in empty sequence instead.
    • You likely need to wrap "isLatestVersion" in sem:iri, e.g. sem:iri("isLatestVersion").
    • Make sure triple index is enabled, though I think it would have complained if you didn't.

    HTH!