Created
August 8, 2011 12:29
-
-
Save ne-sachirou/1131670 to your computer and use it in GitHub Desktop.
CouchDB _design/manage.count_words View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "_design/manage", | |
"language": "javascript", | |
"views": { | |
"count_words": { | |
"map": function(doc) { | |
var wordslist = [ | |
['suki', '好', 'すき', 'スキ', 'スキ'], | |
['kirai', '嫌', 'きらい', 'キライ', 'キライ'], | |
['chiga', '違', 'ちが', 'チガ', 'チガ', 'ちげ', 'チゲ', 'チゲ'] | |
], | |
i, | |
length; | |
wordslist.forEach(function (words) { | |
for (i = 1, length = words.length; i < length; ++i) { | |
if (doc.including_words.indexOf(words[i]) !== -1) { | |
emit(words[0], 1); | |
break; | |
} | |
} | |
}); | |
}, | |
"reduce": function(keys, values, rereduce) { | |
var hash = {'suki': 0, 'kirai': 0, 'chiga': 0}, | |
i, | |
length, | |
prop; | |
if (!rereduce) { | |
for (i = 0, length = keys.length; i < length; ++i) { | |
hash[keys[i][0]] += 1; | |
} | |
} else { | |
for (i = 0, length = values.length; i < length; ++i) { | |
for (prop in hash) { | |
hash[prop] += values[i][prop]; | |
} | |
} | |
} | |
return hash; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ne-sachirou/Draw-graph-from-CouchDB-view
Draw-graph-from-CouchDB-view