
cts.rank( 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. This function works like
math:rank except each item in the sequence is repeated
cts:frequency times before calculating the rank.
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.
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
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.