Browse Source

Use flat point.{lat|lon} in query/reverse.js

pull/271/head
Julian Simioni 9 years ago
parent
commit
109c28a588
  1. 10
      query/reverse.js
  2. 14
      test/unit/query/reverse.js

10
query/reverse.js

@ -38,15 +38,15 @@ function generateQuery( clean ){
} }
// focus point centroid // focus point centroid
if( clean.lat && clean.lon ){ if( clean['point.lat'] && clean['point.lon'] ){
vs.set({ vs.set({
// focus point to score by distance // focus point to score by distance
'focus:point:lat': clean.lat, 'focus:point:lat': clean['point.lat'],
'focus:point:lon': clean.lon, 'focus:point:lon': clean['point.lon'],
// bounding circle // bounding circle
'boundary:circle:lat': clean.lat, 'boundary:circle:lat': clean['point.lat'],
'boundary:circle:lon': clean.lon, 'boundary:circle:lon': clean['point.lon'],
'boundary:circle:radius': radius + 'km' 'boundary:circle:radius': radius + 'km'
}); });
} }

14
test/unit/query/reverse.js

@ -12,7 +12,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.query = function(test, common) { module.exports.tests.query = function(test, common) {
test('valid query', function(t) { test('valid query', function(t) {
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622 'point.lat': 29.49136, 'point.lon': -82.50622
}); });
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
@ -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 'point.lat': 29.49136, 'point.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;
@ -36,15 +36,15 @@ module.exports.tests.query = function(test, common) {
test('valid query with boundary.circle lat/lon/radius', function(t) { test('valid query with boundary.circle lat/lon/radius', function(t) {
var clean = { var clean = {
lat: 29.49136, 'point.lat': 29.49136,
lon: -82.50622, 'point.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);
var compiled = JSON.parse( JSON.stringify( query )).query.filtered.filter.bool.must[0].geo_distance.center_point; var compiled = JSON.parse( JSON.stringify( query )).query.filtered.filter.bool.must[0].geo_distance.center_point;
var expected = { lat: clean.lat, lon: clean.lon }; var expected = { lat: clean['point.lat'], lon: clean['point.lon'] };
t.deepEqual(compiled, expected, 'point.lat/lon overrides boundary.circle.lat/lon'); t.deepEqual(compiled, expected, 'point.lat/lon overrides boundary.circle.lat/lon');
t.end(); t.end();
@ -55,7 +55,7 @@ module.exports.tests.query = function(test, common) {
var sizes = [1,2,10,undefined,null]; var sizes = [1,2,10,undefined,null];
sizes.forEach( function( size ){ sizes.forEach( function( size ){
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622, size: size 'point.lat': 29.49136, 'point.lon': -82.50622, size: size
}); });
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
@ -66,7 +66,7 @@ module.exports.tests.query = function(test, common) {
test('valid boundary.country reverse search', function(t) { test('valid boundary.country reverse search', function(t) {
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622, 'point.lat': 29.49136, 'point.lon': -82.50622,
boundary: { country: 'ABC' } boundary: { country: 'ABC' }
}); });

Loading…
Cancel
Save