You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by muji <fr...@gmail.com> on 2013/03/12 13:42:30 UTC

Sanity check and advice on positional chart query

Hello,

I'm working on an application which has a requirement to list charts
(eg: fan chart/music chart) based on activity which corresponds to a
score.

Currently, I have two document types *score* and *rank*, a score
document represents an individual activity (with a corresponding
score) and a *rank* document is the sum of all *score* documents to
generate a ranking within the chart.

I can provide a list of current chart rankings by querying a view
listing the *rank* documents and ordering by the cumulative score.

We have more complex requirements such as querying by date range and
other criteria which I will try to address later; for the moment my
problem is that I need to calculate the *position* in the chart for a
record.

My current thinking is that if I segregate the charts on a
per-database level and have a view that lists the *rank* documents
then I can use the view *offset* field (+1) to determine the position
in the chart. Do you think this approach is flawed? Is there a better
way to approach the problem?

For paged representations of the chart we plan on deferring the
calculation to the client which can easily determine the position from
current page index, page limit and index into the records. But the
query I am trying to resolve now corresponds to the statement "Your
chart position is 127". I hope that makes sense...

With a very simple test case I've set up using *offset* in this manner
appears to work as expected, I'm wondering if some of the couchdb
people here with more experience than me have any
suggestions/criticisms?

Thanks for any help,

-- 
mischa (aka muji).