MarkLogic 9 Product Documentation
cts:percent-rank

cts:percent-rank(
   $arg as xs:anyAtomicType*,
   $value as xs:anyAtomicType,
   [$options as xs:string*]
) as xs:double?

Summary

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.

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

  xquery version "1.0-ml";

  (:
     This query assumes an int range index
     is configured in the database. It
     generates some sample data and then
     performs the aggregation in a separate
     transaction.
  :)
  for $x in 1 to 10
  return
    xdmp:document-insert(fn:concat($x, ".xml"),
      <my-element>{
        for $y in 1 to $x
        return <int>{$x}</int>
    }</my-element>);

  cts:percent-rank(
    cts:element-values(
      xs:QName("int"), (), ("type=int", "item-frequency")), 9)

  => 0.672727272727273
Powered by MarkLogic Server | Terms of Use | Privacy Policy