> First, change your scores to a numeric instead of a string to make math
> easier.
>
> map:
> function(doc) {
> emit(doc.score, doc.interesting_info);
> }
>
> getRank(score):
> SCORE = user_score+min_score_increment
> results =
> GET("http://127.0.0.1:5984/score_db/_design/high_scores/_view/find_range?startkey=$(SCORE)")
> return results.offset
>
> HTH,
> Paul Davis
>
Whoops! Totally forgot that we wanted this descending.
getRank(score):
results =
GET("http://127.0.0.1:5984/score_db/_design/high_scores/_view/find_rank?startkey=$(score)&descending=true")
return results.total_rows - results.offset + 1
Pretty sure that math is right. Also, I didn't double check that
offsets are calculated in reverse from the beginning. Ie, for
?descending=true&limit=0, offset==total_rows I don't think we do the
math inside CouchDB, but I'm too distracted to look. It'd be a simple
test.
HTH,
Paul Davis