2014-07-08 04:35:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 07:38:03 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
(function(hscd) {
|
|
|
|
var ctx = {};
|
2014-07-28 07:48:24 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
function onAdjust(name, value) {
|
|
|
|
ctx.searchParams[name] = value;
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
var params = {
|
|
|
|
searchParams: ctx.searchParams,
|
|
|
|
searchRange: ctx.searchRange,
|
|
|
|
minScore: ctx.minScore,
|
|
|
|
hintSteps: ctx.hintSteps,
|
|
|
|
maxResults: ctx.maxResults
|
|
|
|
};
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
$.getJSON('/node/search', params, function(results) {
|
|
|
|
var hintData = {};
|
2014-09-12 07:54:21 +00:00
|
|
|
for (var keyword in results.columns) {
|
|
|
|
hintData[keyword] = results.columns[keyword].hints;
|
2014-07-28 13:12:44 +00:00
|
|
|
}
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
ctx.grapher.setColumnHints(hintData);
|
2014-09-16 02:00:15 +00:00
|
|
|
outputResults(results.items, results.count);
|
2014-07-28 13:12:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSearch() {
|
|
|
|
var params = {
|
2014-09-12 07:54:21 +00:00
|
|
|
keywords: $('#keywords').val(),
|
2014-07-28 13:12:44 +00:00
|
|
|
searchRange: { min: -1.0, max: 1.0 },
|
2014-09-13 09:25:33 +00:00
|
|
|
minScore: parseFloat($('#minScore').val()),
|
2014-07-28 13:12:44 +00:00
|
|
|
hintSteps: parseInt($('#hintSteps').val()),
|
|
|
|
maxResults: parseInt($('#maxResults').val())
|
|
|
|
};
|
|
|
|
|
|
|
|
$.getJSON('/node/search', params, function(results) {
|
|
|
|
ctx.searchParams = results.params;
|
|
|
|
ctx.searchRange = params.searchRange;
|
|
|
|
ctx.minScore = params.minScore;
|
|
|
|
ctx.hintSteps = params.hintSteps;
|
|
|
|
ctx.maxResults = params.maxResults;
|
|
|
|
|
2014-09-16 02:17:33 +00:00
|
|
|
ctx.grapher = new Grapher('grapher', ctx.searchRange, 150, true, true);
|
2014-07-28 13:12:44 +00:00
|
|
|
ctx.grapher.setColumns(results.columns);
|
|
|
|
ctx.grapher.setValueChangedListener(onAdjust);
|
|
|
|
|
2014-09-16 02:00:15 +00:00
|
|
|
outputResults(results.items, results.count);
|
2014-07-28 13:12:44 +00:00
|
|
|
|
2014-09-15 08:31:41 +00:00
|
|
|
if (params.keywords) {
|
|
|
|
$('#query').text(params.keywords.join(', '));
|
|
|
|
}
|
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
$('#useLocalScale').click(function() {
|
|
|
|
var useLocalScale = $('#useLocalScale').is(':checked');
|
|
|
|
ctx.grapher.setUseLocalScale(useLocalScale);
|
|
|
|
});
|
|
|
|
$('#useRelativeScale').click(function() {
|
|
|
|
var useRelativeScale = $('#useRelativeScale').is(':checked');
|
|
|
|
ctx.grapher.setUseRelativeScale(useRelativeScale);
|
|
|
|
});
|
|
|
|
$('#input').fadeOut(function() {
|
|
|
|
$('#output').fadeIn();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-09-16 02:00:15 +00:00
|
|
|
function outputResults(results, count) {
|
2014-07-28 13:12:44 +00:00
|
|
|
$('#results').empty();
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-09-16 02:00:15 +00:00
|
|
|
var searchResultCnt = String(results.length);
|
|
|
|
if (results.length < count) {
|
|
|
|
searchResultCnt += ' of ' + count;
|
|
|
|
}
|
|
|
|
$('#count').text(searchResultCnt);
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
var template = Handlebars.compile($('#template').html());
|
|
|
|
$('#results').append(template({'results': results}));
|
|
|
|
}
|
|
|
|
|
2014-09-12 07:54:21 +00:00
|
|
|
$(document).on({
|
|
|
|
ajaxStart: function() {
|
|
|
|
$('#spinner').show();
|
|
|
|
},
|
|
|
|
|
|
|
|
ajaxStop: function() {
|
|
|
|
$('#spinner').hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
ready: function() {
|
2014-09-15 09:35:01 +00:00
|
|
|
$('#keywords').selectpicker();
|
2014-09-15 09:01:22 +00:00
|
|
|
|
2014-09-12 07:54:21 +00:00
|
|
|
$.getJSON('/node/keywords', function(keywords) {
|
|
|
|
for (var i = 0, count = keywords.length; i < count; ++i) {
|
|
|
|
$('#keywords').append($('<option></option>', {
|
|
|
|
value: keywords[i],
|
|
|
|
text: keywords[i]
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2014-09-15 09:35:01 +00:00
|
|
|
$('#keywords').selectpicker('refresh');
|
|
|
|
$('#keywords').change(function() {
|
|
|
|
$('#search').prop('disabled', $(this).val() === null);
|
|
|
|
});
|
|
|
|
|
2014-09-12 07:54:21 +00:00
|
|
|
$('#search').click(onSearch);
|
|
|
|
});
|
|
|
|
}
|
2014-07-26 06:02:42 +00:00
|
|
|
});
|
2014-09-12 07:54:21 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
}(window.hscd = window.hscd || {}));
|