diff --git a/index.js b/index.js index 1c7708b..87d4e82 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,6 @@ module.exports.view = { population: require('./view/population'), popularity_only_function: require('./view/popularity_only_function'), population_only_function: require('./view/population_only_function'), - localregions: require('./view/localregions'), ngrams: require('./view/ngrams'), phrase: require('./view/phrase'), address: require('./view/address'), @@ -29,7 +28,6 @@ module.exports.view = { boundary_rect: require('./view/boundary_rect'), boundary_country: require('./view/boundary_country'), sort_distance: require('./view/sort_distance'), - sort_numeric_script: require('./view/sort_numeric_script'), sources: require('./view/sources'), layers: require('./view/layers'), boundary_gid: require('./view/boundary_gid') diff --git a/test/run.js b/test/run.js index df27d77..5425855 100644 --- a/test/run.js +++ b/test/run.js @@ -20,7 +20,6 @@ var tests = [ require('./view/focus.js'), require('./view/focus_only_function.js'), require('./view/layers.js'), - require('./view/localregions.js'), require('./view/multi_match.js'), require('./view/ngrams.js'), require('./view/phrase.js'), @@ -29,7 +28,6 @@ var tests = [ require('./view/population.js'), require('./view/population_only_function.js'), require('./view/sort_distance.js'), - require('./view/sort_numeric_script.js'), require('./view/sources.js'), require('./view/boundary_gid.js') ]; diff --git a/test/view/localregions.js b/test/view/localregions.js deleted file mode 100644 index a65d4b6..0000000 --- a/test/view/localregions.js +++ /dev/null @@ -1,141 +0,0 @@ -var VariableStore = require('../../lib/VariableStore'); - -function getBaseVariableStore(toExclude) { - var vs = new VariableStore(); - vs.var('focus:point:lat', 'lat value'); - vs.var('focus:point:lon', 'lon value'); - vs.var('centroid:field', 'field value'); - vs.var('localregions:weight', 'weight value'); - vs.var('localregions:function', 'function value'); - vs.var('localregions:offset', 'offset value'); - vs.var('localregions:scale', 'scale value'); - vs.var('localregions:decay', 'decay value'); - - if (toExclude) { - vs.unset(toExclude); - } - - return vs; - -} - -module.exports.tests = {}; - -module.exports.tests.interface = function(test, common) { - test('interface: contructor', function(t) { - var localregions = require('../../view/localregions')(function() {}); - - t.equal(typeof localregions, 'function', 'valid function'); - t.equal(localregions.length, 1, 'takes 1 arg'); - t.end(); - }); - -}; - -module.exports.tests.missing_variable_conditions = function(test, common) { - var variables = Object.keys(getBaseVariableStore().export()); - - variables.forEach(function(missing_variable) { - test('missing required variable should return null', function(t) { - var localregions = require('../../view/localregions')(function() {}); - - var vs = getBaseVariableStore(missing_variable); - - t.equal(localregions(vs), null, 'should have returned null'); - t.end(); - - }); - }); - -}; - -module.exports.tests.no_exceptions_conditions = function(test, common) { - test('all fields available should populate all fields', function(t) { - var localregions = require('../../view/localregions')(); - - var vs = getBaseVariableStore(); - - var actual = localregions(vs); - - var expected = { - function_score: { - functions: [ - { - weight: { $: 'weight value' }, - 'function value': { - 'field value': { - 'origin': { - 'lat': { $: 'lat value' }, - 'lon': { $: 'lon value' } - }, - 'offset': { $: 'offset value' }, - 'scale': { $: 'scale value' }, - 'decay': { $: 'decay value' } - } - } - } - ], - score_mode: 'first', - boost_mode: 'replace' - } - - }; - - t.deepEquals(actual, expected, 'should have returned object'); - t.end(); - - }); - - test('types should be added as a filter', function(t) { - var localregions = require('../../view/localregions')(['type1', 'type2', 'type3']); - - var vs = getBaseVariableStore(); - - var actual = localregions(vs); - - var expected = { - function_score: { - filter: { - 'or': [ - { 'type': { 'value': 'type1' }}, - { 'type': { 'value': 'type2' }}, - { 'type': { 'value': 'type3' }}, - ] - }, - functions: [ - { - weight: { $: 'weight value' }, - 'function value': { - 'field value': { - 'origin': { - 'lat': { $: 'lat value' }, - 'lon': { $: 'lon value' } - }, - 'offset': { $: 'offset value' }, - 'scale': { $: 'scale value' }, - 'decay': { $: 'decay value' } - } - } - } - ], - score_mode: 'first', - boost_mode: 'replace' - } - - }; - - t.deepEquals(actual, expected, 'should have returned object'); - t.end(); - - }); - -}; - -module.exports.all = function (tape, common) { - function test(name, testFunction) { - return tape('localregions ' + name, testFunction); - } - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; diff --git a/test/view/sort_numeric_script.js b/test/view/sort_numeric_script.js deleted file mode 100644 index 977e764..0000000 --- a/test/view/sort_numeric_script.js +++ /dev/null @@ -1,60 +0,0 @@ -var VariableStore = require('../../lib/VariableStore'); - -module.exports.tests = {}; - -module.exports.tests.interface = function(test, common) { - test('interface: contructor', function(t) { - var sort_numeric_script = require('../../view/sort_numeric_script')(function() {}); - - t.equal(typeof sort_numeric_script, 'function', 'valid function'); - t.equal(sort_numeric_script.length, 1, 'takes 1 arg'); - t.end(); - }); - -}; - -module.exports.tests.missing_variable_conditions = function(test, common) { - test('null subview should return null', function(t) { - var sort_numeric_script = require('../../view/sort_numeric_script')(null); - - var vs = new VariableStore(); - - t.equal(sort_numeric_script(vs), null, 'should have returned null'); - t.end(); - - }); - -}; - - -module.exports.tests.no_exceptions_conditions = function(test, common) { - test('all fields available should populate all fields', function(t) { - var sort_numeric_script = require('../../view/sort_numeric_script')('script name value'); - - var vs = new VariableStore(); - - var actual = sort_numeric_script(vs); - - var expected = { - _script: { - file: 'script name value', - type: 'number', - order: 'desc' - } - }; - - t.deepEquals(actual, expected, 'should have returned object'); - t.end(); - - }); - -}; - -module.exports.all = function (tape, common) { - function test(name, testFunction) { - return tape('sort_numeric_script ' + name, testFunction); - } - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; diff --git a/view/localregions.js b/view/localregions.js deleted file mode 100644 index 7145e1f..0000000 --- a/view/localregions.js +++ /dev/null @@ -1,59 +0,0 @@ - -module.exports = function( types ){ - return function( vs ){ - - // validate required params - if( !vs.isset('focus:point:lat') || - !vs.isset('focus:point:lon') || - !vs.isset('centroid:field') || - !vs.isset('localregions:weight') || - !vs.isset('localregions:function') || - !vs.isset('localregions:offset') || - !vs.isset('localregions:scale') || - !vs.isset('localregions:decay') ){ - return null; - } - - // base view - var view = { - function_score: { - // filter: { - // 'or': [ - // { 'type': { 'value': 'locality' } }, - // { 'type': { 'value': 'localadmin' } }, - // { 'type': { 'value': 'neighbourhood' } } - // ] - // }, - // max_boost: 2, - functions: [], - score_mode: 'first', - boost_mode: 'replace' - } - }; - - // a list of _types to target - if( Array.isArray( types ) ){ - view.function_score.filter = { - or: types.map( function( type ){ - return { type: { value: type } }; - }) - }; - } - - // decay function - var func = { weight: vs.var('localregions:weight') }; - func[ vs.var('localregions:function') ] = {}; - func[ vs.var('localregions:function') ][ vs.var('centroid:field') ] = { - origin: { - lat: vs.var('focus:point:lat'), - lon: vs.var('focus:point:lon') - }, - offset: vs.var('localregions:offset'), - scale: vs.var('localregions:scale'), - decay: vs.var('localregions:decay') - }; - view.function_score.functions.push( func ); - - return view; - }; -}; \ No newline at end of file diff --git a/view/sort_numeric_script.js b/view/sort_numeric_script.js deleted file mode 100644 index b6fc44e..0000000 --- a/view/sort_numeric_script.js +++ /dev/null @@ -1,26 +0,0 @@ - -/** - this view is wrapped in a function so it can be re-used for - all numerical sorting scripts. -**/ - -module.exports = function( script_name ){ - return function( vs ){ - - // validate required params - if( !script_name ){ - return null; - } - - // groovy script - var view = { - '_script': { - 'file': script_name, - 'type': 'number', - 'order': 'desc' - } - }; - - return view; - }; -};