From couchdb-user-return-2058-apmail-incubator-couchdb-user-archive=incubator.apache.org@incubator.apache.org Mon Dec 01 19:41:23 2008 Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 14855 invoked from network); 1 Dec 2008 19:41:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Dec 2008 19:41:23 -0000 Received: (qmail 29383 invoked by uid 500); 1 Dec 2008 19:41:32 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 29355 invoked by uid 500); 1 Dec 2008 19:41:32 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 29344 invoked by uid 99); 1 Dec 2008 19:41:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 11:41:32 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 209.85.221.10 as permitted sender) Received: from [209.85.221.10] (HELO mail-qy0-f10.google.com) (209.85.221.10) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 19:40:03 +0000 Received: by qyk3 with SMTP id 3so1766071qyk.12 for ; Mon, 01 Dec 2008 11:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=3TRqgGoGZ6pnNpdbq7LQD3z67auCX9HxsVq0T5PKj+A=; b=h7sDgudzSLFNnDZ5DHpol/DCIsWeWfqJEWoZtLTS2JEFEZfmMxyPlVbJpxoy/+CabD oM8+rqPiYfa6gW2+09UzZAhTdTVFuo1UQPtIKP6aoTC96k9EWN112+y7swFNsnwchkIA 7qSt0MWcQ2adhfbOZ3Agq4iu6XHFxj0O1bnxw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=NMqFlQdKllBzYeaNCxGyfhLPG8xy4ricEhLquVpUJZJXj7q3Ms8qrcdMCnoq03R/AN Dbk2oFkOjjfKfnT9BVZoeaoDRYgvyj0RJ/++myOsLLSnLvBaO7/eVszFz5gIS/sTH1tF Q5A0mBP8UemVvWmGSwZMfw9rPEYn+qwWliMJI= Received: by 10.64.184.18 with SMTP id h18mr11951241qbf.27.1228160449434; Mon, 01 Dec 2008 11:40:49 -0800 (PST) Received: by 10.65.235.11 with HTTP; Mon, 1 Dec 2008 11:40:49 -0800 (PST) Message-ID: Date: Mon, 1 Dec 2008 11:40:49 -0800 From: "Chris Anderson" Sender: jchris@gmail.com To: couchdb-user@incubator.apache.org Subject: Re: Ordering by values calculated by a map/reduce In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: d59ea919e32fbc0a X-Virus-Checked: Checked by ClamAV on apache.org Something like Antony's external handler could be generalized to keep an up to date version of the full results from a group=true reduce query, stored in a secondary database. There are some old threads on the topic, although I'm having trouble bringing them up just now. (Googled "remap") Anyway, by keeping group reduce results (each row to its own document) in another db, you could define a view that ordered them by value. This functionality would be generally useful and could be implemented as an _external, or as regular script triggered by cron. Chris On Sun, Nov 30, 2008 at 11:39 PM, Ben Bangert wrote: > 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 -- Chris Anderson http://jchris.mfdz.com