Skip to content

Instantly share code, notes, and snippets.

@BigBlueHat
Created April 6, 2011 00:06
Show Gist options
  • Save BigBlueHat/904861 to your computer and use it in GitHub Desktop.
Save BigBlueHat/904861 to your computer and use it in GitHub Desktop.
A test of complex keys for listing blog posts...keeping for reference
function(doc) {
// TODO: can we put this someplace "global"?
var max_posts = 10;
if (doc.type == 'page') {
var urlParts = doc.url.split('/');
for (var i in doc.page_items) {
for (var n in doc.page_items[i]) {
if (doc.page_items[i][n].posts != undefined) {
var post_count = 0;
for (var post in doc.page_items[i][n].posts) {
if (post_count == max_posts) break;
emit([urlParts, i, n, doc.page_items[i][n].posts[post].published_date], doc.page_items[i][n].posts[post]);
post_count++;
}
} else {
emit([urlParts, i, n], doc.page_items[i][n]);
}
}
}
emit([urlParts, '_', '_'], {'_id': doc._id});
if (doc.template) {
emit([urlParts, '', 'template'], {'_id':doc.template});
}
emit([urlParts, '', 'site'], {'_id':'site'});
emit([urlParts, '', 'sitemap'], {'_id':'sitemap'});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment