Skip to content

Instantly share code, notes, and snippets.

@panchicore
Created August 14, 2012 19:31
Show Gist options
  • Save panchicore/3352016 to your computer and use it in GitHub Desktop.
Save panchicore/3352016 to your computer and use it in GitHub Desktop.
my map reduces
m = function(){
kws = this.params.marketing_keyword;
if(kws != undefined){
words= kws.replace('+', ' ').split(' ');
for(w in words){
emit({word:words[w]}, {count:1});
}
}
};
r = function(key, values){
c = 0;
values.forEach(function(v){
c += v['count']
});
return {count:c};
}
​db.tracker_event.mapReduce(m, r, {out: {replace:'mr_keyword_count'} });
m = function(){
kw = this.params.marketing_keyword;
if(kw != undefined){
emit({word:kw}, {count:1});
}
};
r = function(key, values){
c = 0;
values.forEach(function(v){
c += v['count']
});
return {count:c};
}
​db.tracker_event.mapReduce(m, r, {out: {replace:'mr_keywords_count'} });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment