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;
}
function findRecords(data, geo, features, minScore) {
function findRecords(data, features, minScore) {
var results = [];
walkMatches(data, features, minScore, function(record, score) {
var distance = 0.0;
if (geo !== null) {
distance = geolib.getDistance(record.geo, geo) / 1000.0;
}
results.push({
name: record.name,
url: 'http://www.tripadvisor.com' + record.relativeUrl,
score: score,
distance: distance,
distance: record.distance,
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) {
getRecords(function(records) {
computeRecordGeo(records, geo);
callback({
keywords: keywords,
records: records
@ -239,10 +244,9 @@ function getParameters(callback) {
}
function execQuery(query, callback) {
getData(function(data) {
getData(query.geo, function(data) {
var searchResults = findRecords(
data,
query.geo,
query.features,
query.minScore
);