Loading TOC...

cts.tripleRangeQuery

cts.tripleRangeQuery(
   $subject as (String | Number | Boolean | null | Array | Object)[],
   $predicate as (String | Number | Boolean | null | Array | Object)[],
   $object as (String | Number | Boolean | null | Array | Object)[],
   [$operator as String[]],
   [$options as String[]],
   [$weight as Number?]
) as cts.tripleRangeQuery

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


declareUpdate();
var sem = require("/MarkLogic/semantics.xqy");
// insert a couple of triples
// make sure the triple index is enabled on the database

var a = sem.rdfInsert(
  sem.triple(sem.iri("http://example.com/ns/directory#m"),
             sem.iri("http://example.com/ns/person#firstName"),
             "Mark"),
  "override-graph=test1");
var b = sem.rdfInsert(
  sem.triple(sem.iri("http://example.com/Mark"),
             sem.iri("http://example.com/ns/person#age"),
             37),
  "override-graph=test1");
var res = new Array();
res.push(a);
res.push(b);
res;

 =>
 ["/triplestore/a805aaab9109e05f.xml", "/triplestore/d58262c00c3ab97f.xml"]

******
// find all documents that have an embedded triple matching Mark-less-than-50
//
// make sure the triple index is enabled on the database

var sem = require("/MarkLogic/semantics.xqy");
var query =
  cts.tripleRangeQuery(
    sem.iri("http://example.com/Mark"),
    sem.iri("http://example.com/ns/person#age"),
    50,
    "<");
var res = [];
for (var x of cts.search(query)) {
	res.push(x.xpath("//sem.triple"));
};
res;

=>
[
"<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>"
]

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy