1

Adding geo preprocessing step

This commit is contained in:
Alex Yatskov 2014-11-17 17:14:41 +09:00
parent 738b97808f
commit 1d70b8bf77

View File

@ -64,19 +64,14 @@ function countRecords(data, features, minScore) {
return count; return count;
} }
function findRecords(data, geo, features, minScore) { function findRecords(data, features, minScore) {
var results = []; var results = [];
walkMatches(data, features, minScore, function(record, score) { walkMatches(data, features, minScore, function(record, score) {
var distance = 0.0;
if (geo !== null) {
distance = geolib.getDistance(record.geo, geo) / 1000.0;
}
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,
distance: distance, distance: record.distance,
id: record.id id: record.id
}); });
}); });
@ -221,9 +216,19 @@ function getRecords(callback) {
}); });
} }
function getData(callback) { function computeRecordGeo(records, geo) {
_.each(records, function(record) {
record.distance = 0.0;
if (geo !== null) {
record.distance = geolib.getDistance(record.geo, geo) / 1000.0;
}
});
}
function getData(geo, callback) {
getKeywords(function(keywords) { getKeywords(function(keywords) {
getRecords(function(records) { getRecords(function(records) {
computeRecordGeo(records, geo);
callback({ callback({
keywords: keywords, keywords: keywords,
records: records records: records
@ -239,10 +244,9 @@ function getParameters(callback) {
} }
function execQuery(query, callback) { function execQuery(query, callback) {
getData(function(data) { getData(query.geo, function(data) {
var searchResults = findRecords( var searchResults = findRecords(
data, data,
query.geo,
query.features, query.features,
query.minScore query.minScore
); );