The docs probably expect prior experience with the search guide and with other 
lexicon functions:

https://docs.marklogic.com/guide/search-dev/aggregate
https://docs.marklogic.com/cts:element-values
https://docs.marklogic.com/cts:values

Here's a simple example:

    for $c in $companies
    let $count := cts:count-aggregate(
      cts:element-reference(xs:QName('id')),
      (),
      cts:element-value-query(xs:QName('company'), $c))
    return text { $c, $count }

Given a sequence of company values, this yields text nodes each containing a 
company value and its count of id elements in the database. If those id 
elements are 1:1 with documents, then this counts documents by company. You 
could add other terms to the cts:query portion, for example restricting it to a 
date range.

This code assumes a range index on element(id), and if it's a string index then 
it must be in the same collation as the query default collation. You could 
change that using the options parameter, currently empty.

-- Mike

On 18 Jul 2014, at 08:34 , Harry Bakken <[email protected]> wrote:

> Is there anyone out there that can point me to some good examples/use cases 
> or documentation for cts:count-aggregate() and even cts:aggregate()?
> 
> The API doc is sort of vague, but I think one or both of these functions can 
> help me with a problem I am trying to solve. I haven't been able to figure 
> out exactly how, though.
> 
> Thanks in advance,
> Harry
> 
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to