Loading TOC...

MarkLogic Server 11.0 Product Documentation
cts:triple-range-query

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

Summary

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.

Parameters
subject The subjects to look up. When multiple values are specified, the query matches if any value matches. When the empty sequence is specified, then triples with any subject are matched.
predicate The predicates to look up. When multiple values are specified, the query matches if any value matches. When the empty sequence is specified, then triples with any predicate are matched.
object The objects to look up. When multiple values are specified, the query matches if any value matches. When the empty sequence is specified, then triples with any object are matched.
operator If a single string is provided it is treated as the operator for the $object values. If a sequence of three strings are provided, they give the operators for $subject, $predicate and $object in turn. The default operator is "=".

Operators include:

"sameTerm"
Match triple index values which are the same RDF term as $value. This compares aspects of values that are ignored in XML Schema comparison semantics, like timezone and derived type of $value.
"<"
Match range index values less than $value.
"<="
Match range index values less than or equal to $value.
">"
Match range index values greater than $value.
">="
Match range index values greater than or equal to $value.
"="
Match range index values equal to $value.
"!="
Match range index values not equal to $value.
options Options to this query. The default is ().

Options include:

"cached"
Cache the results of this query in the list cache.
"uncached"
Do not cache the results of this query in the list cache.
"score-function=function"
Use the selected scoring function. The score function may be:
linear
Use a linear function of the difference between the specified query value and the matching value in the index to calculate a score for this range query.
reciprocal
Use a reciprocal function of the difference between the specified query value and the matching value in the index to calculate a score for this range query.
zero
This range query does not contribute to the score. This is the default.
"slope-factor=number"
Apply the given number as a scaling factor to the slope of the scoring function. The default is 1.0.
weight A weight for this query. The default is 1.0.

Usage Notes

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.

Example

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 iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.