------------------------------ Hi Steve, Fun problem. :)
We could effectively facet by a computed sum, but whether that is practical depends on the cardinality of your facets. If you don't have too many colors, flavors, title, etc, you can compute the sum of the sales value for each unique value, then order them for display purposes. cts:sum lets you do this for sum in the same way cts:frequency lets you do this for count. Unfortunately, there's not an option to return sum instead of count in the SearchAPI, but you could use the rest of the SearchAPI to build your queries and perform other tasks. Putting the sum in the database makes everything pretty easy if you don't think you need to manage updates to those sums. Kelly Message: 2 Date: Thu, 02 Jun 2011 15:47:36 +0100 From: Steve Mallen <[email protected]> Subject: Re: [MarkLogic Dev General] Efficient iterating over values from a large lexicon To: [email protected] Message-ID: <[email protected]> Content-Type: text/plain; charset="utf-8" Hi Nuno, Unfortunately, I don't think it's that simple. I have a set of documents each which each contain a single integer statistic (let's call it "number of sales" for sake of argument). This datum is not computed by our system, but is provided by an external party and matched to each document. Each document (item) also contains metadata about the item, such as title, color, flavour etc. These have been put into lexicons for fast faceting of search results. But we now have a new requirement whereby we want to know the the *total* number of sales for each facet, and show the top ranking (highest total sales) of colors, titles, etc. So I effectively need to order by the sum of all "number of sales" of all items matching a facet. As far as I know there is no way to facet on a computed value. To add to the problem, some of the lexicons have millions of distinct values. Therefore the only solution I can think of is to iterate over all distinct values and pre-compute these values. I can then add a range index on the computed value and order by this sum. Hope I have explained this clearly... -Steve _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
