From user-return-14392-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Tue Jan 04 16:13:43 2011 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 35273 invoked from network); 4 Jan 2011 16:13:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jan 2011 16:13:43 -0000 Received: (qmail 62802 invoked by uid 500); 4 Jan 2011 16:13:41 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 62636 invoked by uid 500); 4 Jan 2011 16:13:40 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 62628 invoked by uid 99); 4 Jan 2011 16:13:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 16:13:40 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_MESSAGE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.210.180] (HELO mail-iy0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 16:13:34 +0000 Received: by iyi12 with SMTP id 12so14469627iyi.11 for ; Tue, 04 Jan 2011 08:13:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.36.12 with SMTP id r12mr6484430ibd.69.1294157591891; Tue, 04 Jan 2011 08:13:11 -0800 (PST) Received: by 10.231.19.6 with HTTP; Tue, 4 Jan 2011 08:13:11 -0800 (PST) Date: Tue, 4 Jan 2011 14:13:11 -0200 Message-ID: Subject: What is the better way to create this kind of view. From: Fabio Batalha Cunha dos Santos To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=0022152d5f718c55f00499078b9c --0022152d5f718c55f00499078b9c Content-Type: text/plain; charset=ISO-8859-1 Hello All, I'm a newbie trying to identify the best way to create a kind of view. For example: My database is something like that: [ {"collection":"scl","issn":"1516-4446","title":"Revista Brasileira de Psiquiatria","subject":["Health Sciences"],"publisher":{"_":"Associa\u00e7\u00e3o Brasileira de Psiquiatria - ABP"},"insert_date":"20000315"}, {"collection":"scl","issn":"0482-5004","title":"Revista Brasileira de Reumatologia","subject":["Health Sciences"],"publisher":{"_":"Elsevier Editora Ltda"},"insert_date":"20051130"}, {"collection":"esp","issn":"1519-3829","title":"Revista Brasileira de Sa\u00fade Materno Infantil ","subject":["Health Sciences","Biological Sciences"],"publisher":{"_":"Instituto de Medicina Integral Prof. Fernando Figueira"},"insert_date":"20030903"}, {"collection":"esp","issn":"1519-6984","title":"Brazilian Journal of Biology","subject":["Health Sciences","Biological Sciences"],"publisher":{"_":"Instituto Internacional de Ecologia"},"insert_date":"20011024"}, {"collection":"scl","issn":"0100-8455","title":"Brazilian Journal of Genetics","subject":["Biological Sciences"],"publisher":{"_":"Sociedade Brasileira de Gen\u00e9tica"},"insert_date":"19970424"}, {"collection":"scl","issn":"1517-8382","title":"Brazilian Journal of Microbiology","subject":["Biological Sciences"],"publisher":{"_":"Sociedade Brasileira de Microbiologia"},"insert_date":"20000811"}, {"collection":"scl","issn":"1677-0420","title":"Brazilian Journal of Plant Physiology","subject":["Biological Sciences"],"publisher":{"_":"Sociedade Brasileira de Fisiologia Vegetal"},"insert_date":"20021023"}, {"collection":"esp","issn":"0101-7438","title":"Pesquisa Operacional","subject":["Engineering"],"publisher":{"_":"Sociedade Brasileira de Pesquisa Operacional"},"insert_date":"20020409"}, ] ** The View* This view must allow to filter data by collection + subject. ** Rules* This view must have 2 keys (collection and subject): ..."key":["esp","Engineering"]... Once the subject attribute could have multiple values,I think the view will have duplicate registers, each one with a different subject in the key attributes, for example. [ {"id":"651197bd-1ee0-46a1-913a-7b5cd6970c4a","key":["esp","Biological Sciences"],"value":{"collection":"esp","issn":"15196984","title":"Brazilian Journal of Biology","subject":["Health Sciences","Biological Sciences"],"publisher":{"_":"Sociedade Brasileira de Gen\u00e9tica"},"insert_date":"20011024"}, {"id":"3f1782f3-9ec5-4f9e-964b-8abc10d4d2cd","key":["esp","Health Sciences"],"value":{"collection":"esp","issn":"15196984","title":"Brazilian Journal of Biology","subject":["Health Sciences","Biological Sciences"],"publisher":{"_":"Sociedade Brasileira de Gen\u00e9tica"},"insert_date":"20011024"}, ] ** How To* (maybe) function(doc) { for (i in doc.subject){ emit(doc.collection, doc.subject], {"collection":doc.collection, "issn":doc.issn, "title": doc.title, "publisher": doc.publisher, "insert_date":doc.insert_date}); } } ** Doubts* Anybody now if this is the best way to create this view? Many Thanks, *Fabio Batalha C. Santos* Colegiado SciELO www.scielo.org FAPESP - CNPq - BIREME - FapUNIFESP --0022152d5f718c55f00499078b9c--