1

Work in progress on getting the "compatible" feature working.

This commit is contained in:
Alex Yatskov 2015-03-17 13:23:32 +09:00
parent d4de2245b2
commit f6c9768fb8
2 changed files with 53 additions and 2 deletions

View File

@ -13,6 +13,7 @@
"express": "~4.5.1", "express": "~4.5.1",
"mysql": "^2.5.0", "mysql": "^2.5.0",
"underscore": "^1.6.0", "underscore": "^1.6.0",
"geolib": "~2.0.14" "geolib": "~2.0.14",
"async": "~0.9.0"
} }
} }

View File

@ -24,6 +24,7 @@
'use strict'; 'use strict';
var _ = require('underscore'); var _ = require('underscore');
var async = require('async');
var geolib = require('geolib'); var geolib = require('geolib');
var mysql = require('mysql'); var mysql = require('mysql');
var pool = null; var pool = null;
@ -160,7 +161,7 @@ function getRecords(context, callback) {
}); });
computeRecordGeo(records, context); computeRecordGeo(records, context);
callback(records); computeRecordCompat(records, context, callback);
}); });
} }
@ -189,6 +190,53 @@ function computeRecordGeo(records, context) {
}); });
} }
function computeRecordCompat(records, context, callback) {
async.map(
records,
function(record, callback) {
pool.query('SELECT * FROM history WHERE reviewId = (?)', [record.id], function(err, rows) {
if (err) {
throw err;
}
async.map(
rows,
function(row, callback) {
pool.query(
'SELECT * FROM historyGroups WHERE historyId = (?)',
[row.id],
function(err, historyGroupRows) {
if (err) {
throw err;
}
var reviewFeatures = {};
_.each(historyGroupRows, function(historyGroupRow) {
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue;
});
var groupScore = innerProduct(context.profile, reviewFeatures);
callback(err, groupScore);
}
);
},
function(err, results) {
if (err) {
throw err;
}
callback(results);
}
);
});
},
function(err, results) {
console.log(results);
callback(records);
}
);
}
function sanitizeQuery(query) { function sanitizeQuery(query) {
var keys = [ var keys = [
'delicious', 'delicious',
@ -197,6 +245,7 @@ function sanitizeQuery(query) {
'atmospheric', 'atmospheric',
'nearby', 'nearby',
'accessible' 'accessible'
// 'compatible'
]; ];
var features = {}; var features = {};
@ -294,6 +343,7 @@ function runQuery(query, callback) {
var context = { var context = {
geo: query.geo, geo: query.geo,
profile: query.profile,
walkingDist: query.walkingDist * 1000.0 walkingDist: query.walkingDist * 1000.0
}; };