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
if( clean.lat && clean.lon ){
if( clean['point.lat'] && clean['point.lon'] ){
vs.set({
// focus point to score by distance
'focus:point:lat': clean.lat,
'focus:point:lon': clean.lon,
'focus:point:lat': clean['point.lat'],
'focus:point:lon': clean['point.lon'],
// bounding circle
'boundary:circle:lat': clean.lat,
'boundary:circle:lon': clean.lon,
'boundary:circle:lat': clean['point.lat'],
'boundary:circle:lon': clean['point.lon'],
'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) {
test('valid query', function(t) {
var query = generate({
lat: 29.49136, lon: -82.50622
'point.lat': 29.49136, 'point.lon': -82.50622
});
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) {
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;
@ -36,15 +36,15 @@ module.exports.tests.query = function(test, common) {
test('valid query with boundary.circle lat/lon/radius', function(t) {
var clean = {
lat: 29.49136,
lon: -82.50622,
'point.lat': 29.49136,
'point.lon': -82.50622,
'boundary.circle.lat': 111,
'boundary.circle.long': 333
};
var query = generate(clean);
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.end();
@ -55,7 +55,7 @@ module.exports.tests.query = function(test, common) {
var sizes = [1,2,10,undefined,null];
sizes.forEach( function( size ){
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 ) );
@ -66,7 +66,7 @@ module.exports.tests.query = function(test, common) {
test('valid boundary.country reverse search', function(t) {
var query = generate({
lat: 29.49136, lon: -82.50622,
'point.lat': 29.49136, 'point.lon': -82.50622,
boundary: { country: 'ABC' }
});

Loading…
Cancel
Save