Modifying keyword computation
This commit is contained in:
parent
8c1279f1ec
commit
8d345fcd11
@ -35,46 +35,48 @@ function add(values1, values2) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function countRecords(data, searchParams, minScore) {
|
function combine(dict, params) {
|
||||||
var dataCount = 0;
|
var result = {};
|
||||||
|
|
||||||
|
for (var key in params) {
|
||||||
|
var values = scale(dict[key], params[key]);
|
||||||
|
result = add(values, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function walkRecords(data, searchParams, minScore, callback) {
|
||||||
|
var features = combine(data.keywords, searchParams);
|
||||||
|
|
||||||
for (var i = 0, count = data.records.length; i < count; ++i) {
|
for (var i = 0, count = data.records.length; i < count; ++i) {
|
||||||
var record = data.records[i];
|
var record = data.records[i];
|
||||||
var score = 0.0;
|
var score = innerProduct(features, record.rating);
|
||||||
|
|
||||||
for (var keyword in searchParams) {
|
|
||||||
var features = scale(data.keywords[keyword], searchParams[keyword]);
|
|
||||||
score += innerProduct(features, record.rating);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (score >= minScore) {
|
if (score >= minScore) {
|
||||||
++dataCount;
|
callback(record, score);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataCount;
|
function countRecords(data, searchParams, minScore) {
|
||||||
|
var count = 0;
|
||||||
|
walkRecords(data, searchParams, minScore, function(record, score) {
|
||||||
|
++count;
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findRecords(data, searchParams, minScore) {
|
function findRecords(data, searchParams, minScore) {
|
||||||
var results = [];
|
var results = [];
|
||||||
|
walkRecords(data, searchParams, minScore, function(record, score) {
|
||||||
for (var i = 0, count = data.records.length; i < count; ++i) {
|
|
||||||
var record = data.records[i];
|
|
||||||
var score = 0.0;
|
|
||||||
|
|
||||||
for (var keyword in searchParams) {
|
|
||||||
var features = scale(data.keywords[keyword], searchParams[keyword]);
|
|
||||||
score += innerProduct(features, record.rating);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (score >= minScore) {
|
|
||||||
results.push({
|
results.push({
|
||||||
name: record.name,
|
name: record.name,
|
||||||
url: 'http://www.tripadvisor.com' + record.relativeUrl,
|
url: 'http://www.tripadvisor.com' + record.relativeUrl,
|
||||||
score: score
|
score: score
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
results.sort(function(a, b) {
|
results.sort(function(a, b) {
|
||||||
return b.score - a.score;
|
return b.score - a.score;
|
||||||
@ -146,20 +148,13 @@ function addKeyword(query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getKeywords(function(keywords) {
|
getKeywords(function(keywords) {
|
||||||
var result = {};
|
var features = combine(keywords, query.params);
|
||||||
for (var param in query.params) {
|
|
||||||
var features = scale(keywords[param], query.params[param]);
|
|
||||||
result = add(result, features);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = scale(result, 1.0 / _.keys(query.params).length);
|
|
||||||
|
|
||||||
var values = [
|
var values = [
|
||||||
query.keyword,
|
query.keyword,
|
||||||
result.food || 0.0,
|
features.food || 0.0,
|
||||||
result.service || 0.0,
|
features.service || 0.0,
|
||||||
result.value || 0.0,
|
features.value || 0.0,
|
||||||
result.atmosphere || 0.0
|
features.atmosphere || 0.0
|
||||||
];
|
];
|
||||||
|
|
||||||
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user