<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.fieldRangeQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.fieldRangeQuery</api:function-name><api:suggest>cts.fieldrangequery</api:suggest><api:suggest>cts</api:suggest><api:suggest>fieldrangequery</api:suggest><api:function-link mode="xquery" fullname="cts:field-range-query">/apidoc/8.0/cts:field-range-query.xml</api:function-link><api:function mode="javascript" name="fieldRangeQuery" 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.fieldRangeQuery"><api:summary>
  Returns a <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code> matching fields by name with a
  range-index entry equal to a given value.  Searches with the
  <code xmlns="http://www.w3.org/1999/xhtml">cts:field-range-query</code>
  constructor require a field range index on the specified field name(s);
  if there is no range index configured, then an exception is thrown.
</api:summary><api:params><api:param name="field-name" type="xs:string*"><api:param-description>
    One or more field names to match. When multiple field names are specified,
    the query matches if any field name matches.
  </api:param-description><api:param-name>field-name</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="operator" type="xs:string"><api:param-description>
    A comparison operator.
    <p xmlns="http://www.w3.org/1999/xhtml">
      Operators include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <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="value" type="xs:anyAtomicType*"><api:param-description>
    One or more field values to match.
    When multiple values are specified,
    the query matches if any value matches.
  </api:param-description><api:param-name>value</api:param-name><api:param-type>(String | Number | Boolean | null)[]</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>"collation=<em>URI</em>"</dt>
        <dd>Use the range index with the collation specified by
        <em>URI</em>.  If not specified, then the default collation
        from the query is used. If a range index with the specified
        collation does not exist, an error is thrown.</dd>
        <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>"min-occurs=<em>number</em>"</dt>
        <dd>Specifies the minimum number of occurrences required. If
        fewer that this number of words occur, the fragment does not match.
        The default is 1.</dd>
        <dt>"max-occurs=<em>number</em>"</dt>
        <dd>Specifies the maximum number of occurrences required.  If
        more than this number of words occur, the fragment does not match.
        The default is unbounded.</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>
        <dt>"synonym"</dt>
        <dd>Specifies that all of the terms in the $value parameter are
        considered synonyms for scoring purposes.  The result is that
        occurrences of more than one of the synonyms are scored as if
        there are more occurrences of the same term (as opposed to
        having a separate term that contributes to score). </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.fieldRangeQuery</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:field-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">
    Negative "min-occurs" or "max-occurs" values will be treated as 0 and
    non-integral values will be rounded down.  An error will be raised if
    the "min-occurs" value is greater than the "max-occurs" value.
  </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">
// Requires a field named "aname" that includes name and excludes mname 
// and a field range index of type xs:string on the field.
//
// Insert few documents with test data
declareUpdate(); 
var content1 = xdmp.unquote(
 '&lt;name&gt;&lt;fname&gt;John&lt;/fname&gt;&lt;mname&gt;Rob&lt;/mname&gt;&lt;lname&gt;Goldings&lt;/lname&gt;&lt;/name&gt;');
var content2 = xdmp.unquote(
 '&lt;name&gt;&lt;fname&gt;Jim&lt;/fname&gt;&lt;mname&gt;Ken&lt;/mname&gt;&lt;lname&gt;Kurla&lt;/lname&gt;&lt;/name&gt;');
var content3 = xdmp.unquote(
 '&lt;name&gt;&lt;fname&gt;Ooi&lt;/fname&gt;&lt;mname&gt;Ben&lt;/mname&gt;&lt;lname&gt;Fu&lt;/lname&gt;&lt;/name&gt;');
var content4 = xdmp.unquote(
 '&lt;name&gt;&lt;fname&gt;James&lt;/fname&gt;&lt;mname&gt;Rick&lt;/mname&gt;&lt;lname&gt;Tod&lt;/lname&gt;&lt;/name&gt;');
xdmp.documentInsert("/aname1.xml", content1);
xdmp.documentInsert("/aname2.xml", content2);
xdmp.documentInsert("/aname3.xml", content3);
xdmp.documentInsert("/aname4.xml", content4);

******

//   requires a field range index of
//   type xs:string on field "aname"

cts.search(cts.fieldRangeQuery("aname","&gt;","Jim Kurla"));

=&gt;
 
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;name&gt;
  &lt;fname&gt;John&lt;/fname&gt;
  &lt;mname&gt;Rob&lt;/mname&gt;
  &lt;lname&gt;Goldings&lt;/lname&gt;
&lt;/name&gt;
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;name&gt;
  &lt;fname&gt;Ooi&lt;/fname&gt;
  &lt;mname&gt;Ben&lt;/mname&gt;
  &lt;lname&gt;Fu&lt;/lname&gt;
&lt;/name&gt;

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