From f6d222b7ec6fc873f6fde924d1fe8a67afc8f3ff Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 14 Sep 2014 19:40:46 +0900 Subject: [PATCH] Fixing rating system --- server/db/search.js | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/server/db/search.js b/server/db/search.js index b2052c3..255e96f 100644 --- a/server/db/search.js +++ b/server/db/search.js @@ -28,12 +28,17 @@ function scale(values, factor) { function countData(searchParams, minScore) { var dataCount = 0; - for (var keyword in searchParams) { - var features = scale(db_keywords[keyword], searchParams[keyword]); - for (var i = 0, count = db_data.length; i < count; ++i) { - if (innerProduct(features, db_data[i].rating) >= minScore) { - ++dataCount; - } + for (var i = 0, count = db_data.length; i < count; ++i) { + var record = db_data[i]; + var score = 0.0; + + for (var keyword in searchParams) { + var features = scale(db_keywords[keyword], searchParams[keyword]); + score += innerProduct(features, record.rating); + } + + if (score >= minScore) { + ++dataCount; } } @@ -43,19 +48,22 @@ function countData(searchParams, minScore) { function findData(searchParams, minScore, maxResults) { var results = []; - for (var keyword in searchParams) { - var features = scale(db_keywords[keyword], searchParams[keyword]); - for (var i = 0, count = db_data.length; i < count; ++i) { - var record = db_data[i]; - var score = innerProduct(features, record.rating); + for (var i = 0, count = db_data.length; i < count; ++i) { + var record = db_data[i]; + var score = 0.0; - if (score >= minScore) { - results.push({ - name: record.name, - url: 'http://www.tripadvisor.com' + record.relativeUrl, - score: score - }); - } + for (var keyword in searchParams) { + var features = scale(db_keywords[keyword], searchParams[keyword]); + score += innerProduct(features, record.rating); + + } + + if (score >= minScore) { + results.push({ + name: record.name, + url: 'http://www.tripadvisor.com' + record.relativeUrl, + score: score + }); } }