1

Add walking distance parameter

This commit is contained in:
Alex Yatskov 2015-01-05 16:26:47 +09:00
parent 0881ecddfc
commit 8162813362
3 changed files with 16 additions and 11 deletions

View File

@ -41,6 +41,10 @@
<label for="searchKeyword">Keyword <span class="label label-warning" id="customized" style="display: none;">Cutomized</span></label> <label for="searchKeyword">Keyword <span class="label label-warning" id="customized" style="display: none;">Cutomized</span></label>
<select id="searchKeyword" class="form-control"></select> <select id="searchKeyword" class="form-control"></select>
</div> </div>
<div class="form-group">
<label for="walkingDist">Walking distance (km)</label>
<input class="form-control" type="number" step="any" value="1.0" id="walkingDist">
</div>
<div class="form-group"> <div class="form-group">
<label for="minScore">Minimum score</label> <label for="minScore">Minimum score</label>
<input class="form-control" type="number" step="any" value="0.25" id="minScore"> <input class="form-control" type="number" step="any" value="0.25" id="minScore">

View File

@ -66,7 +66,7 @@
onSearch(); onSearch();
$('#searchKeyword,#minScore,#hintSteps,#maxResults').change(onSearch); $('#searchKeyword,#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
$('#historyIndex').on('slideStop', onSelectSnapshot); $('#historyIndex').on('slideStop', onSelectSnapshot);
$('#learn').click(onLearn); $('#learn').click(onLearn);
$('#forget').click(onForget); $('#forget').click(onForget);
@ -129,11 +129,12 @@
var keyword = $('#searchKeyword').val(); var keyword = $('#searchKeyword').val();
_ctx.query = { _ctx.query = {
features: _.clone(_ctx.parameters.keywords[keyword]), features: _.clone(_ctx.parameters.keywords[keyword]),
range: { min: -1.0, max: 1.0 }, range: { min: -1.0, max: 1.0 },
minScore: parseFloat($('#minScore').val()), walkingDist: parseFloat($('#walkingDist').val()),
hintSteps: parseInt($('#hintSteps').val()), minScore: parseFloat($('#minScore').val()),
maxResults: parseInt($('#maxResults').val()) hintSteps: parseInt($('#hintSteps').val()),
maxResults: parseInt($('#maxResults').val())
}; };
if (_ctx.geo) { if (_ctx.geo) {

View File

@ -194,7 +194,7 @@ function getKeywords(callback) {
}); });
} }
function getRecords(geo, callback) { function getRecords(geo, walkingDist, callback) {
pool.query('SELECT * FROM reviews', function(err, rows) { pool.query('SELECT * FROM reviews', function(err, rows) {
if (err) { if (err) {
throw err; throw err;
@ -220,7 +220,7 @@ function getRecords(geo, callback) {
}; };
}); });
computeRecordGeo(records, geo, 1000.0); computeRecordGeo(records, geo, walkingDist * 1000.0);
callback(records); callback(records);
}); });
} }
@ -250,9 +250,9 @@ function computeRecordGeo(records, geo, accessDist) {
}); });
} }
function getData(geo, callback) { function getData(geo, walkingDist, callback) {
getKeywords(function(keywords) { getKeywords(function(keywords) {
getRecords(geo, function(records) { getRecords(geo, walkingDist, function(records) {
callback({ callback({
keywords: keywords, keywords: keywords,
records: records records: records
@ -268,7 +268,7 @@ function getParameters(callback) {
} }
function execQuery(query, callback) { function execQuery(query, callback) {
getData(query.geo, function(data) { getData(query.geo, query.walkingDist, function(data) {
var searchResults = findRecords( var searchResults = findRecords(
data, data,
query.features, query.features,