couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "TagsInsideDocuments" by MartinCzura
Date Tue, 07 Oct 2008 02:47:10 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by MartinCzura:
http://wiki.apache.org/couchdb/TagsInsideDocuments

The comment on the change is:
page creation

New page:
Tags are stored as a list of strings inside the document:

{{{
{
 "_id":"123BAC",
 "_rev":"946B7D1C",
 "type":"post",
 "subject":"I like Planktion",
 "author":"Rusty",
 "created":"2006-08-15T17:30:12Z-04:00",
 "body":"I decided today that I don't like baseball. I like plankton.",
 "tags":["plankton", "baseball", "decisions"]
}
}}}

== CouchDB Views ==

'''Retrieve all tags with their counts:'''

''map''

{{{
function(doc) {
  if (doc.type == 'post' && doc.tags) {
    doc.tags.forEach(function(tag) {
      emit(tag, 1);
    });
  }
}
}}}

''reduce''

{{{
function(keys, values) {
  return sum(values);
}
}}}

'''Retrieve documents by a specific tag:'''

''map''

{{{
function(doc) {
  if (doc.type == 'post' && doc.tags) {
    doc.tags.forEach(function(tag) {
      emit(tag, doc);
    });
  }
}
}}}

Mime
View raw message