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

View File

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