Loading TOC...


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


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

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

Options include:

Rank the value as if the sequence was sorted in ascending order.
Rank the value as if the sequence was sorted in descending order.
Applies only when $arg is of the xs:string type. If no specified, the default collation is used.
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.


//  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.


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

// Run the following query:

  cts.jsonPropertyReference("int", "type=int"), null,
                            ["item-frequency"]), 9);
=> 0.672727272727273

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.