Loading TOC...

cts:count

cts:count(
   $arg as item()*,
   [$maximum as xs:double]
) as xs:integer

Summary

[DEPRECATED: use cts:count-aggregate]

Returns a frequency-weighted count of a sequence. This function works like fn:count except the count of each item is multiplied by cts:frequency.

Parameters
arg The sequence of items to count. The items should be the result of a lexicon lookup.
maximum The maximum value of the count to return. MarkLogic Server will stop counting when the $maximum value is reached and return the $maximum value.

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 always be 0.

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:count(cts:element-values(xs:QName("int"), (),
           ("type=int", "item-frequency"))),
cts:count(cts:element-values(xs:QName("int"), (),
           ("type=int", "fragment-frequency")))
=>
55
10


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