I agree on using range indexes, but I think you can do this with the SearchAPI 
instead of the cts built ins.

As soon as you get those counts working, you're going to want to slice things 
with other sorts of queries. It can get to be complex quickly. The SearchAPI 
helps to keep things simple and fast.

Kelly

Message: 1
Date: Wed, 17 Aug 2011 17:05:52 -0700
From: Jason Hunter <jhun...@marklogic.com>
Subject: Re: [MarkLogic Dev General] retrieve values across documents
To: General MarkLogic Developer Discussion
        <general@developer.marklogic.com>
Message-ID: <b10b89b8-d84b-4f97-b9b1-5340d59b1...@marklogic.com>
Content-Type: text/plain; charset=us-ascii

If it's many thousands of documents, you're going to want to use range indexes 
to pull results out of memory and not load documents off disk.

It looks like you want to group into monthly ranges while the specific values 
are specified down to the day.  You can group using "bucketing".  See the 
cts:element-value-ranges() call and specify each month range as a bucket.  Use 
cts:frequency() to get the counts.

I might actually suggest you view the values as strings rather than xs:date 
values to avoid the timezone pain in the neck stuff.

cts:element-value-ranges(
  xs:QName("signed"),
  ("2010-01", "2010-02", "2010-03", ...)
)

If your cardinality is low (meaning the number of months is 100 or less) and 
you're willing for this to take a wee bit longer to execute, you can just do it 
with lots of xdmp:estimate() calls and not bother setting up the range indexes. 
 With that approach you'd do something like this:

xdmp:estimate(cts:search(doc(), cts:element-word-query(xs:QName("signed"), 
"2009-09"))

It'll give you the count for that month, based on substring comparison.  Make 
sure you have fast phrase queries on.  Do a call like this for every month you 
care about.  It'll probably still be very fast.  My guess is you're only doing 
this report once so this is a good way to get the answer without the addition 
of an index, if you don't already have it.

-jh-
_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to