incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Re: group_level and sorting
Date Mon, 20 Apr 2009 13:39:37 GMT
On Apr 20, 2009, at 9:51 AM, Nicolas Clairon wrote:

> = Reducing to get summary =
>
> So, we have 3 documents A (with "title1" as title) but I want to
> display only one to my users.
> The displayed document will show the most releval informations (the
> most use description) and
> all the tags. So I created a reduce function wich summaries all the 3
> documents into a single one :
>
> reduced_documentA = {
>  "title":"title1",
>  "description":"a document A",
>  "tags":["tag1","tag2","tag3"],
>  "date_creation": 1
> }
>
> Note that the reduced document took the earlier date_creation.

Hmmm... Remember that reduce results should not grow faster than  
log(n) for n documents. If everyone uses a different tag, that can  
become a problem. Of course, if you're not expecting thousands of  
tags, that shouldn't be a real issue.

> = Displaying the reduce document =
>
> The challenge now, is to display the reduced document by tags then by
> date_creation.
>
> That's all.
>
> How can I do that ? If I use a map function :
>
>  emit([doc.tag[t], doc.date_creation], doc.title);
>
> i will have duplication.

So use

emit([doc.tag[t], doc.date_creation, doc.title], null);

No duplication.

> I thought that I can user external process for that. Each time the
> reduced_document
> is updated, external process will store the reduced_document as
> regular document in
> another db (so that I can query it simplier).

The problem is, knowing when the reduced_document is updated. You  
could get updates when a document is inserted and then query your  
reduced view, to see if the reduced document changed, and if so insert  
it in your database again.

Wout.

Mime
View raw message