On Mon, Apr 20, 2009 at 3:39 PM, Wout Mertens <[email protected]> wrote: > 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.
I don't expect thousands of tags but it might be possible that each document is so different that I can have "nb_results_map" = "nb_results_reduce" (if, for instance, the description is different for each document). How can I handle this 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. I found a solution : process this by program. Each time user create a DocumentA, I copy the reduced result into another database as a document (if the document already exists, I'll updated it). I could use update notifications but couchdb is not verbose enougth. I can't get the id of the updated document. Nicolas
