diff --git a/helper/query_parser.js b/helper/query_parser.js index cee589b0..4af009aa 100644 --- a/helper/query_parser.js +++ b/helper/query_parser.js @@ -9,7 +9,7 @@ module.exports = {}; module.exports.get_layers = function get_layers(query) { if (query.length <= 3 ) { // no address parsing required - return type_mapping.layer_to_type.coarse; + return type_mapping.layer_with_aliases_to_type.coarse; } }; diff --git a/helper/type_mapping.js b/helper/type_mapping.js index 0ac2a30d..d2b0f758 100644 --- a/helper/type_mapping.js +++ b/helper/type_mapping.js @@ -1,3 +1,5 @@ +var extend = require('extend'); + var ALL_TYPES = [ 'geoname', 'osmnode', @@ -55,7 +57,7 @@ var SOURCE_TO_TYPE = { }; /** - * This includeds alias layers + * This does not included alias layers, those are built separately */ var LAYER_TO_TYPE = { 'venue': ['geoname','osmnode','osmway'], @@ -65,14 +67,20 @@ var LAYER_TO_TYPE = { 'county': ['admin2'], 'locality': ['locality'], 'localadmin': ['local_admin'], - 'neighbourhood': ['neighborhood'], - 'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'], + 'neighbourhood': ['neighborhood'] +}; + +var LAYER_ALIASES = { + 'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'] }; +var LAYER_WITH_ALIASES_TO_TYPE = extend({}, LAYER_ALIASES, LAYER_TO_TYPE); + module.exports = { types_list: ALL_TYPES, type_to_source: TYPE_TO_SOURCE, type_to_layer: TYPE_TO_LAYER, source_to_type: SOURCE_TO_TYPE, - layer_to_type: LAYER_TO_TYPE + layer_to_type: LAYER_TO_TYPE, + layer_with_aliases_to_type: LAYER_WITH_ALIASES_TO_TYPE }; diff --git a/sanitiser/reverse.js b/sanitiser/reverse.js index 11937bbc..154fd3d9 100644 --- a/sanitiser/reverse.js +++ b/sanitiser/reverse.js @@ -3,7 +3,7 @@ var type_mapping = require('../helper/type_mapping'); var sanitizeAll = require('../sanitiser/sanitizeAll'), sanitizers = { singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), - layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type), + layers: require('../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type), sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type), size: require('../sanitiser/_size'), private: require('../sanitiser/_flag_bool')('private', false), diff --git a/sanitiser/search.js b/sanitiser/search.js index dd46f419..cc596b26 100644 --- a/sanitiser/search.js +++ b/sanitiser/search.js @@ -5,7 +5,7 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'), singleScalarParameters: require('../sanitiser/_single_scalar_parameters'), text: require('../sanitiser/_text'), size: require('../sanitiser/_size'), - layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type), + layers: require('../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type), sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type), private: require('../sanitiser/_flag_bool')('private', false), geo_search: require('../sanitiser/_geo_search'), diff --git a/test/unit/helper/query_parser.js b/test/unit/helper/query_parser.js index c1e3fd52..02c96531 100644 --- a/test/unit/helper/query_parser.js +++ b/test/unit/helper/query_parser.js @@ -1,7 +1,7 @@ var parser = require('../../../helper/query_parser'); var type_mapping = require('../../../helper/type_mapping'); -var layers_map = type_mapping.layer_to_type; +var layers_map = type_mapping.layer_with_aliases_to_type; module.exports.tests = {}; diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 1d1c945e..fa50c191 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -30,7 +30,13 @@ module.exports.tests.interfaces = function(test, common) { test('layer to type mapping', function(t) { t.ok(check.object(type_mapping.layer_to_type), 'is object'); - t.ok(check.hasLength(Object.keys(type_mapping.layer_to_type), 9), 'has correct number of elements'); + t.equal(Object.keys(type_mapping.layer_to_type).length, 8, 'has correct number of elements'); + t.end(); + }); + + test('layer to type mapping (with aliases)', function(t) { + t.ok(check.object(type_mapping.layer_with_aliases_to_type), 'is object'); + t.ok(check.hasLength(Object.keys(type_mapping.layer_with_aliases_to_type), 9), 'has correct number of elements'); t.end(); }); }; diff --git a/test/unit/sanitiser/_layers.js b/test/unit/sanitiser/_layers.js index 50117c08..519d95d9 100644 --- a/test/unit/sanitiser/_layers.js +++ b/test/unit/sanitiser/_layers.js @@ -1,6 +1,6 @@ var type_mapping = require('../../../helper/type_mapping'); -var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_to_type); +var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type); module.exports.tests = {};