user6768802
user6768802

Reputation:

Find the frequency of non-lexicon values in xquery

Is there any way to find the frequency of an element that does not have a range index ? the

cts:frequency() that I use does not support any element that is not lexicon

Upvotes: 1

Views: 118

Answers (1)

Dave Cassel
Dave Cassel

Reputation: 8422

You'll need some type of index in order to get counts. Besides a range index, here's an approach using a word lexicon:

for $word in cts:element-words(xs:QName("city"))
return 
  $word || " " || 
  xdmp:estimate(
    cts:search(
      fn:doc(), 
      cts:element-word-query(xs:QName("city"), $word)))

Understand that this approach might not give you the values you're expecting if you have multi-word values. For instance, if you have <city>San Francisco</city> and <city>San Diego</city>, you'll get these counts:

  • san: 2
  • francisco: 1
  • diego: 1

For getting accurate, value-based counts, a range index is your best bet.

Upvotes: 5

Related Questions