I'm trying to implement the reddit algorithm as a sorting option in my app but I'm constantly hitting walls all over the place.
I started my implementation using this (Sorting mongodb by reddit ranking algorithm) post as a guide line.
I tried to convert it to c#; below is my attempt at the conversion.
var map = new BsonJavaScript(
@"function() {
function hot(score, date){
var order = log10(Math.max(Math.abs(score), 1));
var sign = score>0 ? 1 : score<0 ? -1 : 0;
var seconds = epochSeconds(date) - 1134028003;
var product = order + sign * seconds / 45000;
return Math.round(product*10000000)/10000000;
}
function log10(val){
return Math.log(val) / Math.LN10;
}
function epochSeconds(d){
return (d.getTime() - new Date(1970,1,1).getTime())/1000;
}
emit( hot(this.VoteCount, this.CreatedAt), this );
}"
);
var reduce = new BsonJavaScript(
@"function(){}"
);
var finalize = new BsonJavaScript(
@"{ 'out': { 'inline': 1 } }"
);
return db.Posts.MapReduce(new MapReduceArgs { MapFunction = map, ReduceFunction = reduce, FinalizeFunction = finalize }).GetResults();
He's the results I'm getting from the implementation;

He's the actual dataset.

For some reason the function returns 2 objects instead of 4. Also, what would I need to modify for the function to return the entire post object along with the calculated score?
Would really appreciate it if someone would help me out :)
Thanks in advance, Jean