
cts:triple-range-query( $subject as xs:anyAtomicType*, $predicate as xs:anyAtomicType*, $object as xs:anyAtomicType*, [$operator as xs:string*], [$options as xs:string*], [$weight as xs:double?] ) as cts:triple-range-query
  Returns a 
  cts:query
  matching triples with a
  triple index entry equal to the given values. Searches with the
  cts:triple-range-query
  constructor require the triple index;
  if the triple index is not configured, then an exception is thrown.
If you want to constrain on a range of values, you can combine multiple
  cts:triple-range-query
  constructors together
  with 
  cts:and-query
  or any of the other composable
  cts:query
  constructors.
If neither "cached" nor "uncached" is present, it specifies "cached".
"score-function=linear" means that values that are further away from the bounds will score higher. "score-function=reciprocal" means that values that are closer to the bounds will score higher. The functions are scaled appropriately for different types, so that in general the default slope factor will provide useful results. Using a slope factor greater than 1 gives distinct scores over a smaller range of values, and produces generally higher scores. Using a slope factor less than 1 gives distinct scores over a wider range of values, and produces generally lower scores.
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at
"/MarkLogic/semantics.xqy";
(: insert a couple of triples :)
sem:rdf-insert(
  sem:triple(sem:iri("http://example.com/ns/directory#m"),
             sem:iri("http://example.com/ns/person#firstName"),
             "Mark"),
  "override-graph=test1") ,
sem:rdf-insert(
  sem:triple(sem:iri("http://example.com/Mark"),
             sem:iri("http://example.com/ns/person#age"),
             37),
  "override-graph=test1")
 =>
 /triplestore/46a9deab2e3d1e5a.xml
 /triplestore/b954ee9d04dc536d.xml
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
    at "/MarkLogic/semantics.xqy";
(: find all documents that have an embedded triple matching Mark-less-than-50 :)
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:collection()//sem:triple, $query)
=>
<sem:triple xmlns:sem="http://marklogic.com/semantics">
  <sem:subject>http://example.com/Mark</sem:subject>
  <sem:predicate>http://example.com/ns/person#age</sem:predicate>
  <sem:object
    datatype="http://www.w3.org/2001/XMLSchema#integer">37</sem:object>
</sem:triple>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.