<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.tripleRangeQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.tripleRangeQuery</api:function-name><api:suggest>cts.triplerangequery</api:suggest><api:suggest>cts</api:suggest><api:suggest>triplerangequery</api:suggest><api:function-link mode="xquery" fullname="cts:triple-range-query">/apidoc/8.0/cts:triple-range-query.xml</api:function-link><api:function mode="javascript" name="tripleRangeQuery" type="builtin" lib="cts" category="SearchBuiltins" subcategory="cts:query Constructors" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.tripleRangeQuery"><api:summary>
  Returns a <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code> matching triples with a
  triple index entry equal to the given values. Searches with the
  <code xmlns="http://www.w3.org/1999/xhtml">cts:triple-range-query</code> constructor require the triple index;
  if the triple index is not configured, then an exception is thrown.
</api:summary><api:params><api:param name="subject" type="xs:anyAtomicType*"><api:param-description>
    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.
  </api:param-description><api:param-name>subject</api:param-name><api:param-type>(String | Number | Boolean | null)[]</api:param-type></api:param><api:param name="predicate" type="xs:anyAtomicType*"><api:param-description>
    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.
  </api:param-description><api:param-name>predicate</api:param-name><api:param-type>(String | Number | Boolean | null)[]</api:param-type></api:param><api:param name="object" type="xs:anyAtomicType*"><api:param-description>
    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.
  </api:param-description><api:param-name>object</api:param-name><api:param-type>(String | Number | Boolean | null)[]</api:param-type></api:param><api:param name="operator" type="xs:string*" optional="true"><api:param-description>
    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 "=".
    <p xmlns="http://www.w3.org/1999/xhtml">
      Operators include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"sameTerm"</dt>
        <dd>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.</dd>
        <dt>"&lt;"</dt>
        <dd>Match range index values less than $value.</dd>
        <dt>"&lt;="</dt>
        <dd>Match range index values less than or equal to $value.</dd>
        <dt>"&gt;"</dt>
        <dd>Match range index values greater than $value.</dd>
        <dt>"&gt;="</dt>
        <dd>Match range index values greater than or equal to $value.</dd>
        <dt>"="</dt>
        <dd>Match range index values equal to $value.</dd>
        <dt>"!="</dt>
        <dd>Match range index values not equal to $value.</dd>
      </dl></blockquote>
  </api:param-description><api:param-name>operator</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options to this query.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">
      Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"cached"</dt>
        <dd>Cache the results of this query in the list cache.</dd>
        <dt>"uncached"</dt>
        <dd>Do not cache the results of this query in the list cache.</dd>
        <dt>"score-function=<em>function</em>"</dt>
        <dd>Use the selected scoring function. The score function may be:
          <dl>
          <dt>linear</dt><dd>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.</dd>
          <dt>reciprocal</dt><dd>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.</dd>
          <dt>zero</dt><dd>This range query does not contribute to the
          score. This is the default.</dd>
          </dl>
        </dd>
        <dt>"slope-factor=<em>number</em>"</dt>
        <dd>Apply the given number as a scaling factor to the slope of the
        scoring function. The default is 1.0.</dd>
      </dl></blockquote>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="weight" type="xs:double?" optional="true"><api:param-description>
    A weight for this query.  The default is 1.0.
  </api:param-description><api:param-name>weight</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return>cts.tripleRangeQuery</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">If you want to constrain on a range of values, you can combine multiple
  <code>cts:triple-range-query</code> constructors together
  with <code>cts:and-query</code> or any of the other composable
  <code>cts:query</code> constructors.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If neither "cached" nor "uncached" is present, it specifies "cached".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">"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.
  </p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

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;

 =&gt;
 ["/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,
    "&lt;");
cts.search(query).next().value.xpath("//sem.triple");

=&gt;
[
"&lt;sem:triple xmlns:sem="http://marklogic.com/semantics"&gt;
  &lt;sem:subject&gt;http://example.com/Mark&lt;/sem:subject&gt;
  &lt;sem:predicate&gt;http://example.com/ns/person#age&lt;/sem:predicate&gt;
  &lt;sem:object 
    datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;37&lt;/sem:object&gt;
&lt;/sem:triple&gt;"
]

</pre>
</api:example></api:function></api:function-page>