1

Removing unnecessary returned data from server

This commit is contained in:
Alex Yatskov 2014-09-18 16:24:40 +09:00
parent 4c64c428c6
commit 5c9ddb7c0d
2 changed files with 23 additions and 31 deletions

View File

@ -7,7 +7,7 @@
function onAdjust(name, value) { function onAdjust(name, value) {
ctx.searchParams[name] = value; ctx.searchParams[name] = value;
var params = { var query = {
searchParams: ctx.searchParams, searchParams: ctx.searchParams,
searchRange: ctx.searchRange, searchRange: ctx.searchRange,
minScore: ctx.minScore, minScore: ctx.minScore,
@ -15,7 +15,7 @@
maxResults: ctx.maxResults maxResults: ctx.maxResults
}; };
$.getJSON('/node/search', params, function(results) { $.getJSON('/node/search', query, function(results) {
var hintData = {}; var hintData = {};
for (var keyword in results.columns) { for (var keyword in results.columns) {
hintData[keyword] = results.columns[keyword].hints; hintData[keyword] = results.columns[keyword].hints;
@ -27,20 +27,27 @@
} }
function onSearch() { function onSearch() {
var params = { var keywords = $('#keywords').val() || [];
keywords: $('#keywords').val(), var searchParams = {};
for (var i = 0, count = keywords.length; i < count; ++i) {
searchParams[keywords[i]] = 1.0;
}
var query = {
searchParams: searchParams,
searchRange: { min: -1.0, max: 1.0 }, searchRange: { min: -1.0, max: 1.0 },
minScore: parseFloat($('#minScore').val()), minScore: parseFloat($('#minScore').val()),
hintSteps: parseInt($('#hintSteps').val()), hintSteps: parseInt($('#hintSteps').val()),
maxResults: parseInt($('#maxResults').val()) maxResults: parseInt($('#maxResults').val())
}; };
$.getJSON('/node/search', params, function(results) { $.getJSON('/node/search', query, function(results) {
ctx.searchParams = results.params; ctx.searchParams = query.searchParams;
ctx.searchRange = params.searchRange; ctx.searchRange = query.searchRange;
ctx.minScore = params.minScore; ctx.minScore = query.minScore;
ctx.hintSteps = params.hintSteps; ctx.hintSteps = query.hintSteps;
ctx.maxResults = params.maxResults; ctx.maxResults = query.maxResults;
ctx.grapher = new Grapher('grapher', ctx.searchRange, 150, true, true); ctx.grapher = new Grapher('grapher', ctx.searchRange, 150, true, true);
ctx.grapher.setColumns(results.columns); ctx.grapher.setColumns(results.columns);
@ -48,10 +55,7 @@
outputResults(results.items, results.count); outputResults(results.items, results.count);
if (params.keywords) { $('#query').text(keywords.join(', '));
$('#query').text(params.keywords.join(', '));
}
$('#useLocalScale').click(function() { $('#useLocalScale').click(function() {
var useLocalScale = $('#useLocalScale').is(':checked'); var useLocalScale = $('#useLocalScale').is(':checked');
ctx.grapher.setUseLocalScale(useLocalScale); ctx.grapher.setUseLocalScale(useLocalScale);
@ -99,12 +103,11 @@
})); }));
} }
$('#search').click(onSearch);
$('#keywords').selectpicker('refresh'); $('#keywords').selectpicker('refresh');
$('#keywords').change(function() { $('#keywords').change(function() {
$('#search').prop('disabled', $(this).val() === null); $('#search').prop('disabled', $(this).val() === null);
}); });
$('#search').click(onSearch);
}); });
} }
}); });

View File

@ -182,16 +182,6 @@ function getData(callback) {
function execQuery(query, callback) { function execQuery(query, callback) {
getData(function(data) { getData(function(data) {
if (!query.searchParams) {
query.searchParams = {};
for (var i = 0, count = query.keywords.length; i < count; ++i) {
var keyword = query.keywords[i];
if (_.has(data.keywords, keyword)) {
query.searchParams[keyword] = 1.0;
}
}
}
var searchResults = findRecords( var searchResults = findRecords(
data, data,
query.searchParams, query.searchParams,
@ -219,7 +209,6 @@ function execQuery(query, callback) {
callback({ callback({
columns: graphColumns, columns: graphColumns,
params: query.searchParams,
items: searchResults.slice(0, query.maxResults), items: searchResults.slice(0, query.maxResults),
count: searchResults.length count: searchResults.length
}); });