incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Bangert <...@groovie.org>
Subject Ordering by values calculated by a map/reduce
Date Mon, 01 Dec 2008 07:39:01 GMT
I want to solve what I thought was a fairly simple problem, though  
unfortunately it seems to be rather tricky. I asked on the IRC  
channel, and got some good input, but neither really seemed like a  
very good solution.

The problem:

I want to allow users to rate things. They do this very very  
frequently, so I can't store it in the actual document being rated, so  
I have Rating documents. It's easy enough to write a map/reduce that  
gives me the computed average rating for a given document, however, it  
seems to be impossible to get a listing of the highest rated  
documents, as I can only get the computed rating for a document one at  
a time.

The possible solutions:
- Buffer rating additions, then at a later time, run through them and  
calculate the new average rating, store it in the document as  
computed_rating, so I can order on that in the key
- Cron a job that goes in and looks for new rating every 5 mins or  
whatever, and then does the same as the previous solution by storing  
it in a computed_rating field

I'm not a fan of either of these, because #1 means if my webapp  
hiccups, I lose ratings, and #2 is just a pain to keep sweeping the db  
for new Rating documents then going through updating all the documents.

Is there really no other solutions that don't require me to store the  
computed rating in the doc itself? There's no way I can perhaps order  
on the value from the map/reduce, rather than only being able to order  
on the key?

Thanks,
Ben
Mime
View raw message