From 1402d601007e2cefb3bc61001179c521867941ae Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 20 Mar 2015 20:15:47 +0900 Subject: [PATCH] Create compatibility feature --- server/search.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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); } );