Skip to content

Instantly share code, notes, and snippets.

@rakyll
Created June 3, 2013 12:25
Show Gist options
  • Save rakyll/5697772 to your computer and use it in GitHub Desktop.
Save rakyll/5697772 to your computer and use it in GitHub Desktop.
{
"_id": "_design/tags",
"_rev": "70-302fb6b6b2181d491b4cc75a6c0c29b5",
"language": "javascript",
"views": {
"relations": {
"map": "function(doc) {\n var mainTag = doc.tag.toLowerCase();\n var tags = doc.text.toLowerCase().split(' ').filter(function (word) {\n return word[0] === '#' && word !== mainTag;\n });\n\n tags.forEach(function(tag) {\n emit(mainTag, tag);\n });\n}",
"reduce": "function(keys, values, rereduce) {\n var mapping = {};\n \n if (rereduce) {\n values.forEach(function (val) {\n for (var tag in val)\n mapping[tag] = (mapping[tag] || 0) + val[tag];\n });\n } else {\n values.forEach(function (val) {\n mapping[val] = (mapping[val] || 0) + 1;\n });\n }\n \n return mapping;\n}"
},
"relations_recent": {
"map": "function(doc) {\n if (Date.now() - (new Date(doc.created_at)) >= 600000)\n return;\n\n var mainTag = doc.tag.toLowerCase();\n var tags = doc.text.toLowerCase().split(' ');\n var tag;\n\n for (var i=tags.length-1; i>=0; i--) {\n tag = tags[i];\n if (tag[0] !== '#' || tag === mainTag) continue;\n emit(mainTag, tag);\n };\n}",
"reduce": "function(keys, values, rereduce) {\n var mapping = {};\n \n if (rereduce) {\n values.forEach(function (val) {\n for (var tag in val)\n mapping[tag] = (mapping[tag] || 0) + val[tag];\n });\n } else {\n values.forEach(function (val) {\n mapping[val] = (mapping[val] || 0) + 1;\n });\n }\n \n return mapping;\n}"
},
"total_recent": {
"map": "function(doc) {\n if (Date.now() - (new Date(doc.created_at)) >= 600000)\n return;\n\n var tags = doc.entities && doc.entities.hashtags;\n if (tags) {\n for (var i=tags.length-1; i >= 0; i--)\n emit(tags[i].text, 1);\n } else {\n tags = doc.text.toLowerCase().split(' ');\n var tag;\n\n for (var i=tags.length-1; i>=0; i--) {\n tag = tags[i];\n if (tag[0] !== '#') continue;\n emit(tag.substring(1), 1);\n }\n }\n}",
"reduce": "_sum"
}
},
"_attachments": {
"recent_tag_cloud.html": {
"content_type": "text/html",
"revpos": 70,
"digest": "md5-1K7JMuJFpYLNPh5uqrHlQQ==",
"length": 2354,
"stub": true
},
"dynamic-bubble.html": {
"content_type": "text/html",
"revpos": 68,
"digest": "md5-E1T2kZWHtk584dqeNWYnuQ==",
"length": 3048,
"stub": true
},
"bubble.html": {
"content_type": "text/html",
"revpos": 67,
"digest": "md5-DhxTxFcDD5Vzb9bH8SOoAA==",
"length": 2510,
"stub": true
},
"d3.v3.js": {
"content_type": "application/x-javascript",
"revpos": 3,
"digest": "md5-KSSDHTLPkgfGm6ZUqh4tuA==",
"length": 298053,
"stub": true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment