Browse Source

Add a separate default distance for coarse reverse

pull/549/head
Julian Simioni 9 years ago
parent
commit
c9d87f7b0c
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 1
      query/reverse_defaults.js
  2. 5
      sanitiser/_geo_reverse.js
  3. 26
      test/unit/sanitiser/_geo_reverse.js

1
query/reverse_defaults.js

@ -13,6 +13,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'sort:distance:distance_type': 'plane',
'boundary:circle:radius': '1km',
'boundary:circle:radius:coarse': '500km',
'boundary:circle:distance_type': 'plane',
'boundary:circle:optimize_bbox': 'indexed',
'boundary:circle:_cache': true,

5
sanitiser/_geo_reverse.js

@ -29,8 +29,13 @@ module.exports = function sanitize( raw, clean ){
// if no radius was passed, set the default
if ( _.isUndefined( raw['boundary.circle.radius'] ) ) {
// the default is small unless layers other than venue or address were explicitly specified
if (clean.layers && clean.layers.length > 0 && !_.includes(clean.layers, 'venue') && !_.includes(clean.layers, 'address')) {
raw['boundary.circle.radius'] = defaults['boundary:circle:radius:coarse'];
} else {
raw['boundary.circle.radius'] = defaults['boundary:circle:radius'];
}
}
// santize the boundary.circle
geo_common.sanitize_circle( 'boundary.circle', clean, raw, CIRCLE_IS_REQUIRED );

26
test/unit/sanitiser/_geo_reverse.js

@ -85,6 +85,32 @@ module.exports.tests.sanitize_boundary_country = function(test, common) {
t.end();
});
test('no boundary.circle.radius and coarse layers supplied should be set to coarse default', function(t) {
var raw = {
'point.lat': '12.121212',
'point.lon': '21.212121'
};
var clean = { layers: 'coarse' };
var errorsAndWarnings = sanitize(raw, clean);
t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius:coarse'], 'should be from defaults');
t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius:coarse']), 'should be same as raw');
t.end();
});
test('no boundary.circle.radius and coarse layer supplied should be set to coarse default', function(t) {
var raw = {
'point.lat': '12.121212',
'point.lon': '21.212121'
};
var clean = { layers: 'locality' };
var errorsAndWarnings = sanitize(raw, clean);
t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius:coarse'], 'should be from defaults');
t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius:coarse']), 'should be same as raw');
t.end();
});
test('explicit boundary.circle.radius should be used instead of default', function(t) {
var raw = {
'point.lat': '12.121212',

Loading…
Cancel
Save