Created
September 4, 2015 16:53
-
-
Save glamp/942a46b7b29bb447805f to your computer and use it in GitHub Desktop.
Revisions
-
glamp created this gist
Sep 4, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ var map = function() { var summary = this.message_soup_text; if (summary) { // quick lowercase to normalize per your requirements summary = summary.toLowerCase().split(" "); for (var i = summary.length - 1; i >= 0; i--) { // might want to remove punctuation, etc. here if (summary[i]) { // make sure there's something emit(summary[i], 1); // store a 1 for each word } } } }; var reduce = function( key, values ) { var count = 0; values.forEach(function(v) { count +=v; }); return count; } // full thing // db.support_emails.mapReduce(map, reduce, { out: "word_count" }) // subset db.support_emails.mapReduce(map, reduce, {limit: 1000, out: "word_count" }) db.word_count.find().sort({ value: -1 }).limit(10)