Ranking now being computed properly
This commit is contained in:
parent
076baa1204
commit
cfd5ca4670
@ -210,9 +210,6 @@ function computeRecordCompat(records, context, callback) {
|
||||
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue;
|
||||
});
|
||||
|
||||
console.log(context.profile);
|
||||
console.log(reviewFeatures);
|
||||
console.log('***\n');
|
||||
var groupScore = innerProduct(context.profile, reviewFeatures);
|
||||
callback(err, groupScore);
|
||||
}
|
||||
@ -231,18 +228,23 @@ function computeRecordCompat(records, context, callback) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
_.each(records, function(record) {
|
||||
if (record.groupScores.length > 0) {
|
||||
console.log(record);
|
||||
}
|
||||
});
|
||||
|
||||
callback(records);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function sanitizeQuery(query) {
|
||||
function fixupProfile(profile) {
|
||||
var fixed = {};
|
||||
_.each(JSON.parse(profile), function(value, key) {
|
||||
if (parseFloat(value) !== 0) {
|
||||
fixed[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return fixed;
|
||||
}
|
||||
|
||||
function fixupFeatures(features) {
|
||||
var keys = [
|
||||
'delicious',
|
||||
'accomodating',
|
||||
@ -253,19 +255,12 @@ function sanitizeQuery(query) {
|
||||
'compatible'
|
||||
];
|
||||
|
||||
var features = {};
|
||||
var fixed = {};
|
||||
_.each(keys, function(key) {
|
||||
features[key] = _.has(query.features, key) ? query.features[key] : 0;
|
||||
fixed[key] = _.has(features, key) ? features[key] : 0;
|
||||
});
|
||||
query.features = features;
|
||||
|
||||
var profile = {};
|
||||
_.each(JSON.parse(query.profile), function(key, value) {
|
||||
if (parseFloat(value) !== 0) {
|
||||
profile[key] = value;
|
||||
}
|
||||
});
|
||||
query.profile = profile;
|
||||
return fixed;
|
||||
}
|
||||
|
||||
function getCategories(callback) {
|
||||
@ -314,6 +309,8 @@ function removeCategory(query, callback) {
|
||||
}
|
||||
|
||||
function accessReview(query, callback) {
|
||||
query.profile = fixupProfile(query.profile);
|
||||
|
||||
pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@ -326,6 +323,7 @@ function accessReview(query, callback) {
|
||||
if (results.success) {
|
||||
results.url = 'http://www.tripadvisor.com' + rows[0].url;
|
||||
|
||||
if (_.keys(query.profile).length > 0) {
|
||||
pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@ -339,13 +337,15 @@ function accessReview(query, callback) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
callback(results);
|
||||
});
|
||||
}
|
||||
|
||||
function runQuery(query, callback) {
|
||||
sanitizeQuery(query);
|
||||
query.profile = fixupProfile(query.profile);
|
||||
query.features = fixupFeatures(query.features);
|
||||
|
||||
var context = {
|
||||
geo: query.geo,
|
||||
|
Loading…
Reference in New Issue
Block a user