Skip to content

Instantly share code, notes, and snippets.

@ne-sachirou
Created August 8, 2011 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ne-sachirou/1131670 to your computer and use it in GitHub Desktop.
Save ne-sachirou/1131670 to your computer and use it in GitHub Desktop.
CouchDB _design/manage.count_words View
{
"_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;
}
}
}
}
@ne-sachirou
Copy link
Author

https://github.com/ne-sachirou/Draw-graph-from-CouchDB-view
Draw-graph-from-CouchDB-view

var timerid = setInterval(function () {update()}, 300000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment