couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabio Batalha Cunha dos Santos <fabio.bata...@scielo.org>
Subject What is the better way to create this kind of view.
Date Tue, 04 Jan 2011 16:13:11 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message