1

Server cleanup

This commit is contained in:
Alex Yatskov 2014-07-28 15:41:14 +09:00
parent ffbaaf6f71
commit 54a22051b6
3 changed files with 87 additions and 84 deletions

View File

@ -11,20 +11,20 @@ function outputResults(results, maxResults) {
} }
function onAdjust(name, value) { function onAdjust(name, value) {
var wa = window.adjuster; // var wa = window.adjuster;
var wg = window.grapher; // var wg = window.grapher;
wa.queryParams[name] = value; // wa.searchParams[name] = value;
console.log(wa.queryParams); // console.log(wa.searchParams);
var hintData = {}; // var hintData = {};
_.each(wg.getColumnNames(), function(name) { // _.each(wg.getColumnNames(), function(name) {
hintData[name] = searchBuildHints(wa.queryParams, wa.minScore, name, wa.searchRange, wa.hintSteps); // hintData[name] = searchBuildHints(wa.searchParams, wa.minScore, name, wa.searchRange, wa.hintSteps);
}); // });
wg.setColumnHints(hintData); // wg.setColumnHints(hintData);
var results = searchData(wa.queryParams, wa.minScore); // var results = searchData(wa.searchParams, wa.minScore);
outputResults(results, wa.maxResults); // outputResults(results, wa.maxResults);
} }
function onSearch() { function onSearch() {
@ -38,59 +38,37 @@ function onSearch() {
}; };
$.getJSON('/node/search', params, function(results) { $.getJSON('/node/search', params, function(results) {
alert('searched'); console.log(results);
});
// var queryParams = DATA_KEYWORDS[query]; window.adjuster = {
// var searchRange = new goog.math.Range(-1.0, 1.0); searchParams: results.params,
// var graphColumns = {}; minScore: params.minScore,
hintSteps: params.hintSteps,
maxResults: params.maxResults
};
// for (var feature in queryParams) { window.grapher = new Grapher('grapher', new goog.math.Range(-1.0, 1.0), params.useLocalScale, params.useRelativeScale);
// var hints = searchBuildHints( window.grapher.setColumns(results.columns);
// queryParams, window.grapher.setValueChangedListener(onAdjust);
// minScore,
// feature,
// searchRange,
// hintSteps
// );
// graphColumns[feature] = { // var results = searchData(searchParams, minScore);
// 'color': '#607080',
// 'value': queryParams[feature],
// 'hints': hints,
// 'steps': hintSteps
// }
// }
// window.adjuster = {
// queryParams: queryParams,
// searchRange: searchRange,
// hintSteps: hintSteps,
// minScore: minScore,
// maxResults: maxResults
// };
// window.grapher = new Grapher('grapher', searchRange, useLocalScale, useRelativeScale);
// window.grapher.setColumns(graphColumns);
// window.grapher.setValueChangedListener(onAdjust);
// var results = searchData(queryParams, minScore);
// outputResults(results, maxResults); // outputResults(results, maxResults);
// $('#query').text(query); $('#query').text(params.keyword);
// $('#useLocalScale').prop('checked', useLocalScale); $('#useLocalScale').prop('checked', useLocalScale);
// $('#useRelativeScale').prop('checked', useRelativeScale); $('#useRelativeScale').prop('checked', useRelativeScale);
// $('#useLocalScale').click(function() { $('#useLocalScale').click(function() {
// var useLocalScale = $('#useLocalScale').is(':checked'); var useLocalScale = $('#useLocalScale').is(':checked');
// window.grapher.setUseLocalScale(useLocalScale); window.grapher.setUseLocalScale(useLocalScale);
// }); });
// $('#useRelativeScale').click(function() { $('#useRelativeScale').click(function() {
// var useRelativeScale = $('#useRelativeScale').is(':checked'); var useRelativeScale = $('#useRelativeScale').is(':checked');
// window.grapher.setUseRelativeScale(useRelativeScale); window.grapher.setUseRelativeScale(useRelativeScale);
// }); });
// $('#input').fadeOut(function() { $('#input').fadeOut(function() {
// $('#output').fadeIn(); $('#output').fadeIn();
// }); });
});
} }
$(document).ready(function() { $(document).ready(function() {

View File

@ -1,11 +1,12 @@
'use strict'; 'use strict';
var _ = require('underscore'); var _ = require('underscore');
var keywords = require('./keywords.json'); var db_keywords = require('./keywords.json');
var data = require('./data.json'); var db_data = require('./data.json');
function innerProduct(values1, values2) { function innerProduct(values1, values2) {
var result = 0; var result = 0;
for (var feature in values1) { for (var feature in values1) {
result += values1[feature] * (values2[feature] || 0.0); result += values1[feature] * (values2[feature] || 0.0);
} }
@ -13,12 +14,12 @@ function innerProduct(values1, values2) {
return result; return result;
} }
function searchData(queryParams, minScore) { function searchData(searchParams, minScore) {
var results = []; var results = [];
for (var i = 0, count = DATA_RECORDS.length; i < count; ++i) { for (var i = 0, count = db_data.length; i < count; ++i) {
var record = DATA_RECORDS[i]; var record = db_data[i];
var score = innerProduct(queryParams, record['rating']); var score = innerProduct(searchParams, record['rating']);
if (score >= minScore) { if (score >= minScore) {
results.push({ results.push({
@ -37,10 +38,10 @@ function searchData(queryParams, minScore) {
} }
function searchStepper(range, steps, callback) { function searchStepper(range, steps, callback) {
var stepSize = range.getLength() / steps; var stepSize = (range.max - range.min) / steps;
for (var i = 0; i < steps; ++i) { for (var i = 0; i < steps; ++i) {
var stepMax = range.end - stepSize * i; var stepMax = range.max - stepSize * i;
var stepMin = stepMax - stepSize; var stepMin = stepMax - stepSize;
var stepMid = (stepMin + stepMax) / 2; var stepMid = (stepMin + stepMax) / 2;
@ -48,8 +49,8 @@ function searchStepper(range, steps, callback) {
} }
} }
function searchProjection(queryParams, minScore, feature, range, steps) { function searchProjection(searchParams, minScore, feature, range, steps) {
var testParams = _.clone(queryParams); var testParams = _.clone(searchParams);
var results = []; var results = [];
searchStepper(range, steps, function(position) { searchStepper(range, steps, function(position) {
@ -63,8 +64,8 @@ function searchProjection(queryParams, minScore, feature, range, steps) {
return results; return results;
} }
function searchProjection2d(queryParams, minScore, feature1, feature2, range, steps) { function searchProjection2d(searchParams, minScore, feature1, feature2, range, steps) {
var testParams = _.clone(queryParams); var testParams = _.clone(searchParams);
var results = []; var results = [];
searchStepper(range, steps, function(sampleX) { searchStepper(range, steps, function(sampleX) {
@ -82,9 +83,9 @@ function searchProjection2d(queryParams, minScore, feature1, feature2, range, st
return results; return results;
} }
function searchBuildHints(queryParams, minScore, feature, range, steps) { function searchBuildHints(searchParams, minScore, feature, range, steps) {
var projection = searchProjection( var projection = searchProjection(
queryParams, searchParams,
minScore, minScore,
feature, feature,
range, range,
@ -102,9 +103,9 @@ function searchBuildHints(queryParams, minScore, feature, range, steps) {
return hints; return hints;
} }
function searchBuildHints2d(queryParams, minScore, feature1, feature2, range, steps) { function searchBuildHints2d(searchParams, minScore, feature1, feature2, range, steps) {
var projection = searchProjection2d( var projection = searchProjection2d(
queryParams, searchParams,
minScore, minScore,
feature1, feature1,
feature2, feature2,
@ -125,9 +126,33 @@ function searchBuildHints2d(queryParams, minScore, feature1, feature2, range, st
} }
module.exports.getKeywords = function() { module.exports.getKeywords = function() {
return _.keys(keywords); return _.keys(db_keywords);
} }
module.exports.execQuery = function() { module.exports.execQuery = function(query) {
return {}; var searchParams = db_keywords[query.keyword];
var searchRange = { 'min': -1.0, 'max': 1.0 };
var graphColumns = { };
for (var feature in searchParams) {
var hints = searchBuildHints(
searchParams,
query.minScore,
feature,
searchRange,
query.hintSteps
);
graphColumns[feature] = {
'color': '#607080',
'value': searchParams[feature],
'hints': hints,
'steps': query.hintSteps
}
}
return {
'columns': graphColumns,
'params': searchParams
};
} }

View File

@ -15,7 +15,7 @@ function main() {
app.use('/search', function(req, res) { app.use('/search', function(req, res) {
console.log('Requesting search'); console.log('Requesting search');
res.json(search.execQuery()); res.json(search.execQuery(req.query));
}); });
app.listen(3000); app.listen(3000);