diff --git a/server/search.js b/server/search.js index 0dc20da..bdf41a3 100644 --- a/server/search.js +++ b/server/search.js @@ -193,6 +193,9 @@ function computeRecordGeo(records, context) { } function computeRecordPopularity(records, context, callback) { + var scoreMin = 0; + var scoreMax = 0; + async.each( records, function(record, callback) { @@ -213,12 +216,18 @@ function computeRecordPopularity(records, context, callback) { }); var groupScore = innerProduct(context.profile, reviewFeatures); + scoreMin = Math.min(scoreMin, groupScore); + scoreMax = Math.max(scoreMax, groupScore); + callback(err, groupScore); } ); }, function(err, groupScores) { - record.groupScores = groupScores; + var scoreSum = _.reduce(groupScores, function(a, b) { return a + b; }); + var scoreAvg = scoreSum / groupScores.length; + + record.features.compatibility = (scoreAvg - scoreMin) / (scoreMax - scoreMin); callback(err); } );