Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created August 25, 2010 12:14
Show Gist options
  • Save yusukebe/549381 to your computer and use it in GitHub Desktop.
Save yusukebe/549381 to your computer and use it in GitHub Desktop.
my $map = <<MAP;
function() {
if( this.comment != null && this.date > $date ){
try{
this.comment.match(/(@[a-zA-Z0-9_]+)/);
emit(RegExp.\$1, 1);
}catch(e){
}
}
}
MAP
my $reduce = <<REDUCE;
function(k,vals) {
var sum = 0;
for( var i in vals) sum += vals[i];
return sum;
}
REDUCE
my $cmd = Tie::IxHash->new(
"mapreduce" => "post",
"map" => $map,
"reduce" => $reduce,
"query" => 'type.sale',
);
my $res = $db->run_command($cmd);
my $col = $res->{result};
my @rows =
$db->$col->query( {}, { limit => 100, sort_by => { value => -1 } } )->all();
$db->$col->drop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment