<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.rank.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.rank</api:function-name><api:suggest>cts.rank</api:suggest><api:suggest>cts</api:suggest><api:suggest>rank</api:suggest><api:function-link mode="xquery" fullname="cts:rank">/apidoc/8.0/cts:rank.xml</api:function-link><api:function mode="javascript" name="rank" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Math Lexicon" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.rank"><api:summary>
  Returns the rank of a value in a data set. This function works like
  <code xmlns="http://www.w3.org/1999/xhtml">math:rank</code> except each item in the sequence is repeated
  <code xmlns="http://www.w3.org/1999/xhtml">cts:frequency</code> times before calculating the rank.
</api:summary><api:params><api:param name="arg" type="xs:anyAtomicType*"><api:param-description>
  The sequence of values.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>(String | Number | Boolean | null)[]</api:param-type></api:param><api:param name="value" type="xs:anyAtomicType"><api:param-description>
  The value to be "ranked".
  </api:param-description><api:param-name>value</api:param-name><api:param-type>xs.anyAtomicType</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">
      Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"ascending"(default)</dt>
        <dd>Rank the value as if the sequence was sorted in ascending order.
        </dd>
        <dt>"descending"</dt>
        <dd>Rank the value as if the sequence was sorted in descending order.
        </dd>
        <dt>"collation=<em>URI</em>"</dt>
        <dd>Applies only when $arg is of the xs:string type. If no specified,
        the default collation is used.</dd>
        <dt>"coordinate-system=<em>name</em>"</dt>
        <dd>Applies only when $arg is of the cts:point type. If no specified,
        the default coordinate system is used.</dd>
      </dl></blockquote>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>Number?</api:return><api:usage>
 <p xmlns="http://www.w3.org/1999/xhtml">This function is designed to take a sequence of values returned
 by a lexicon function (for example, <code>cts:element-values</code>); if you
 input non-lexicon values, the result will be the empty sequence.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//  This query assumes an element range index of type 'int'
//  is configured for the 'int' element in the database. It
//  generates some sample data and then performs the aggregation
//  in a separate transaction.

declareUpdate();

for (x=1; x&lt;11; x++) {
  var o = new Object();
  o.int = [];
  for (y=x; y&lt;11; y++) { 
    o.int.push(y);    
  };
  xdmp.documentInsert((x + ".json"), o); 
};

******
// Run the following query:

cts.rank(cts.values(
  cts.jsonPropertyReference("int", "type=int"), null,
                            ["item-frequency"]), 9);
=&gt; 37


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