Browse Source

Change boundary.circle params to flat string structure

pull/271/head
Julian Simioni 9 years ago
parent
commit
4260442f59
  1. 4
      query/reverse.js
  2. 4
      query/search.js
  3. 6
      sanitiser/_geo_common.js
  4. 6
      test/unit/query/reverse.js
  5. 2
      test/unit/query/search.js
  6. 9
      test/unit/sanitiser/_geo_common.js

4
query/reverse.js

@ -33,8 +33,8 @@ function generateQuery( clean ){
// set radius, default to 500km if not specified in request // set radius, default to 500km if not specified in request
var radius = 500; var radius = 500;
if (clean.hasOwnProperty('boundary_circle_radius')) { if (clean.hasOwnProperty('boundary.circle.radius')) {
radius = clean.boundary_circle_radius; radius = clean['boundary.circle.radius'];
} }
// focus point centroid // focus point centroid

4
query/search.js

@ -97,9 +97,9 @@ function generateQuery( clean ){
} }
// boundary country // boundary country
if( clean.boundary && clean.boundary.country ){ if( clean['boundary.country'] ){
vs.set({ vs.set({
'boundary:country': clean.boundary.country 'boundary:country': clean['boundary.country']
}); });
} }

6
sanitiser/_geo_common.js

@ -64,9 +64,9 @@ function sanitize_coord( coord, clean, param, latlon_is_required ) {
*/ */
function sanitize_boundary_circle( clean, params, is_required, all_required ) { function sanitize_boundary_circle( clean, params, is_required, all_required ) {
var props = { var props = {
lat: 'boundary_circle_lat', lat: 'boundary.circle.lat',
lon: 'boundary_circle_lon', lon: 'boundary.circle.lon',
rad: 'boundary_circle_radius' rad: 'boundary.circle.radius'
}; };
// get values for each property // get values for each property

6
test/unit/query/reverse.js

@ -24,7 +24,7 @@ module.exports.tests.query = function(test, common) {
test('valid query with radius', function(t) { test('valid query with radius', function(t) {
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622, boundary_circle_radius: 123 lat: 29.49136, lon: -82.50622, 'boundary.circle.radius': 123
}); });
var compiled = JSON.parse( JSON.stringify( query )).query.filtered.filter.bool.must[0].geo_distance.distance; var compiled = JSON.parse( JSON.stringify( query )).query.filtered.filter.bool.must[0].geo_distance.distance;
@ -38,8 +38,8 @@ module.exports.tests.query = function(test, common) {
var clean = { var clean = {
lat: 29.49136, lat: 29.49136,
lon: -82.50622, lon: -82.50622,
boundary_circle_lat: 111, 'boundary.circle.lat': 111,
boundary_circle_long: 333 'boundary.circle.long': 333
}; };
var query = generate(clean); var query = generate(clean);

2
test/unit/query/search.js

@ -138,7 +138,7 @@ module.exports.tests.query = function(test, common) {
var query = generate({ var query = generate({
text: 'test', size: 10, text: 'test', size: 10,
layers: ['test'], layers: ['test'],
boundary: { country: 'ABC' } 'boundary.country': 'ABC'
}); });
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );

9
test/unit/sanitiser/_geo_common.js

@ -23,11 +23,12 @@ module.exports.tests.sanitize = function(test, common) {
var all_required = true; var all_required = true;
sanitize.sanitize_boundary_circle(clean, params, is_required, all_required); sanitize.sanitize_boundary_circle(clean, params, is_required, all_required);
t.equal(clean.boundary_circle_lat, params['boundary.circle.lat'], 'lat approved'); t.equal(clean['boundary.circle.lat'], params['boundary.circle.lat'], 'lat approved');
t.equal(clean.boundary_circle_lon, params['boundary.circle.lon'], 'lon approved'); t.equal(clean['boundary.circle.lon'], params['boundary.circle.lon'], 'lon approved');
t.equal(clean.boundary_circle_radius, params['boundary.circle.radius'], 'radius approved'); t.equal(clean['boundary.circle.radius'], params['boundary.circle.radius'], 'radius approved');
t.end(); t.end();
}); });
test('valid circle, radius only, all not required', function (t) { test('valid circle, radius only, all not required', function (t) {
var clean = {}; var clean = {};
var params = { var params = {
@ -37,7 +38,7 @@ module.exports.tests.sanitize = function(test, common) {
var all_required = false; var all_required = false;
sanitize.sanitize_boundary_circle(clean, params, is_required, all_required); sanitize.sanitize_boundary_circle(clean, params, is_required, all_required);
t.equal(clean.boundary_circle_radius, params['boundary.circle.radius'], 'radius approved'); t.equal(clean['boundary.circle.radius'], params['boundary.circle.radius'], 'radius approved');
t.end(); t.end();
}); });
}; };

Loading…
Cancel
Save