4

What is the difference between cts:count, cts:frequency, fn:count in MarkLogic?

Could you please support me with example?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Ahmad Tamimi
  • 261
  • 1
  • 2
  • 8

1 Answers1

6

cts:count

is deprecated and it was 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.

You should use cts:count-aggregate instead.

The cts:count-aggregate function works like cts:count except it performs the counting in parallel in all data nodes then aggregates the values. It generally performs better than cts:count, especially on large clusters

See: https://docs.marklogic.com/cts:count-aggregate

cts:frequency

Returns an integer representing the number of times in which a particular value occurs in a value lexicon lookup (for example, cts:element-values). When using the fragment-frequency lexicon option, cts:frequency returns the number of fragments in which the lexicon value occurs. When using the item-frequency lexicon option, cts:frequency returns the total number of times in which the lexicon value occurs in each item.

See https://docs.marklogic.com/cts:frequency

fn:count

Returns the number of items in a sequence

See https://docs.marklogic.com/fn:count

See the different links for samples

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
prker
  • 494
  • 2
  • 3
  • Thanks Prker, Actually I already read the documentation before submitting this question But I didn't got the point, also their example is not clear at all. at least if they put the file content of the example. by the way thanks again, I would like to ask u if u can support me with a different and more clear example. – Ahmad Tamimi Jan 14 '16 at 07:10
  • Note also the benefits of speed if you use `xdmp:estimate` at http://docs.marklogic.com/xdmp:estimate. If it's possible to use `xdmp:estimate`, my understanding is that the speed is much faster. I also understand from the article that `xdmp:estimate` can be mostly accurate, but because it uses JUST indexes to search, it may not be fully accurate. If a rough estimate is acceptable, sounds good to me. – CtheGood Jan 14 '16 at 22:23
  • xdmp:estimate is faster because it draws only on the indexes. It's accuracy depends on how well the configured indexes support what you're trying to estimate. fn:count loops through a list to count it; it can be slow, especially if it needs to pull docs from disk. [Good read to compare the two.](https://docs.marklogic.com/guide/search-dev/count_estimate) – Dave Cassel Jan 19 '16 at 13:44