Skip to content

Instantly share code, notes, and snippets.

@electronicbites
Created July 4, 2011 15:20
Show Gist options
  • Save electronicbites/1063477 to your computer and use it in GitHub Desktop.
Save electronicbites/1063477 to your computer and use it in GitHub Desktop.
reduce function for couch
{
"_id": "_design/num_ar_id",
"_rev": "36-145879462ded07757a29757bb5b5b92b",
"language": "javascript",
"views": {
"count_of_ar_id": {
"map": "function(doc) {\n if (doc.ar_id) {\n emit(doc.ad_id, doc.ar_id );\n }\n}",
"reduce": "function(keys, values, rereduce) {\n if (rereduce) {\n return sum(values);\n }\n else {\n return values.length;\n }\n}"
},
"count_of_ar_id_impl": {
"map": "function(doc) {\n if (doc.ar_id && doc.subject_id && doc.ad_id) {\n emit([doc.subject_id, doc.ad_id, doc.ar_id, doc.url], doc.ar_id );\n }\n}",
"reduce": "_count"
},
"select_ar_id": {
"map": "// map\nfunction(doc) {\n if (doc.ar_id) {\n emit(doc.ar_id, null);\n }\n}"
},
"sum_values_ar_id": {
"map": "function(doc) {\n emit(ar_id, 1);\n}",
"reduce": "function(keys, values) {\n return sum(values);\n}"
},
"select_subject_id": {
"map": "// map\nfunction(doc) {\n if (doc.subject_id) {\n emit(doc.subject_id, doc);\n }\n}"
}
},
"lists": {
"simple": "function(head, req) {var row; send(\"begin\");\n while(row = getRow()) {\n send(row.value);\n send(row.key);\n }\n send(\"end\");\n}",
"csv": "function(head, req) {var row; while(row = getRow()){send(row.key);send(',');send(row.value);send('\\n');}send('\\n');send('\\n');send('END');}",
"export-ar_ids": "function(head, req) { \n var row\n var rows=[]\n while(row = getRow()) { \n rows.push(row) \n } \n rows.sort(function(a,b) { \n return b.value-a.value\n }) \n send(JSON.stringify({\"rows\" : rows}))\n}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment