Hi Helen,

You can take Danny's approach a few steps further to use range indexes for 
everything.

Something like:

let $codens := cts:element-values(xs:QName("coden"),(),(),cts:and-query(())) 
for $c in $codens 
return
        <coden name="{$c}">
        {
                let $volumes := 
cts:element-values(xs:QName("volume"),(),cts:element-range-query(xs:QName("coden"),"=",$c))
                for $v in $volumes
                return
                <volume name="{$v}">
                {
                        let $issues := 
cts:element-values(xs:QName("article"),(),cts:and-query((cts:element-range-query(xs:QName("volume"),"=",$v),
 cts:element-range-query(xs:QName("coden"),"=",$c))))
                        for $i in $issues
                        return  <issue name="{$i}"/>
                }
                </volume>
        }
        </coden>

Let us know if this helps and we may be able to do some further optimization.

Kelly

PS - you could probably add cts:frequency() to each level in the tree to get 
counts if you'd like.

Message: 1
Date: Tue, 6 Apr 2010 14:48:31 -0700
From: Danny Sokolsky <[email protected]>
Subject: RE: [MarkLogic Dev General] how to build the tree based on
        data
To: General Mark Logic Developer Discussion
        <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

If there is a range index on coden, then you can substitute the:

fn:distinct-values(//coden)

with 

cts:element-values(xs:QName("coden"))

That should speed things up a bit....

-Danny


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

Reply via email to