Loading TOC...

cts.rank

cts.rank(
   $arg as (String | Number | Boolean | null | Array | Object)[],
   $value as xs.anyAtomicType,
   [$options as String[]]
) as Number?

Summary

Returns the rank of a value in a data set. This function works like math:rank except each item in the sequence is repeated cts:frequency times before calculating the rank.

Parameters
$arg The sequence of values.
$value The value to be "ranked".
$options Options. The default is ().

Options include:

"ascending"(default)
Rank the value as if the sequence was sorted in ascending order.
"descending"
Rank the value as if the sequence was sorted in descending order.
"collation=URI"
Applies only when $arg is of the xs:string type. If no specified, the default collation is used.
"coordinate-system=name"
Applies only when $arg is of the cts:point type. If no specified, the default coordinate system is used.

Usage Notes

This function is designed to take a sequence of values returned by a lexicon function (for example, cts:element-values); if you input non-lexicon values, the result will be the empty sequence.

Example

//  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<11; x++) {
  var o = new Object();
  o.int = [];
  for (y=x; y<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);
=> 37


Comments

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