diff --git a/controller/search.js b/controller/search.js index 9666cc49..8c9f7970 100644 --- a/controller/search.js +++ b/controller/search.js @@ -22,8 +22,8 @@ function setup( backend, query ){ } // set type if input suggests targeting a layer(s) - if (req.clean.parsed_input) { - cmd.type = req.clean.parsed_input.target_layer; + if (req.clean.default_layers_set && req.clean.parsed_input) { + cmd.type = req.clean.parsed_input.target_layer || cmd.type; } // query backend diff --git a/sanitiser/_input.js b/sanitiser/_input.js index d65cf60d..42a65fd8 100644 --- a/sanitiser/_input.js +++ b/sanitiser/_input.js @@ -48,6 +48,10 @@ function sanitize( req ){ // set target_layer if input suggests no address if (parsedAddress1.text === parsedAddress1.regions.join(' ')) { parsedAddress2.target_layer = get_layers(['admin', 'poi']); + } else { + // this might be an overkill - you'd want to search for poi and admin + // even if an address is being queried. TBD + parsedAddress2.target_layer = get_layers(['address']); } } diff --git a/sanitiser/_layers.js b/sanitiser/_layers.js index f61bb9a3..fa44336e 100644 --- a/sanitiser/_layers.js +++ b/sanitiser/_layers.js @@ -17,6 +17,7 @@ function sanitize( req ){ // default case (no layers specified in GET params) if('string' !== typeof params.layers || !params.layers.length){ params.layers = 'poi,admin,address'; // default layers + clean.default_layers_set = true; } // decide which layers can be queried diff --git a/test/unit/sanitiser/reverse.js b/test/unit/sanitiser/reverse.js index bb1a6a98..90366a41 100644 --- a/test/unit/sanitiser/reverse.js +++ b/test/unit/sanitiser/reverse.js @@ -10,6 +10,7 @@ var suggest = require('../../../sanitiser/reverse'), lon: 0, size: 10, details: true, + default_layers_set: true, categories: [] }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); };