From 57f969117ef4465096336fc6c2165bf1eaa59d53 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 22 Sep 2014 17:06:29 -0400 Subject: [PATCH 1/2] fixing the bbox issue. constructing a 20km bbox and not some insanely big bounding box. --- middleware/search.js | 8 ++++---- query/search.js | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/middleware/search.js b/middleware/search.js index ec3d88e2..e2fdba63 100644 --- a/middleware/search.js +++ b/middleware/search.js @@ -26,7 +26,7 @@ function WGS84EarthRadius(lat){ function boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm) { var lat = deg2rad(latitudeInDegrees); var lon = deg2rad(longitudeInDegrees); - var halfSide = 1000000*halfSideInKm; + var halfSide = 1000*halfSideInKm; // Radius of Earth at given latitude var radius = WGS84EarthRadius(lat); @@ -39,11 +39,11 @@ function boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm) { var lonMax = lon + halfSide/pradius; return { - 'top_left': { + 'bottom_left': { 'lat': rad2deg(latMin), 'lon': rad2deg(lonMin) }, - 'bottom_right': { + 'top_right': { 'lat': rad2deg(latMax), 'lon': rad2deg(lonMax) } @@ -57,7 +57,7 @@ function middleware(req, res, next){ req.clean = req.clean || {}; // ideally, bbox should be part of the req (and not to be calculated) // TBD - req.clean.bbox = boundingBox(req.query.lat, req.query.lon, 2000); + req.clean.bbox = boundingBox(req.query.lat, req.query.lon, 20); next(); } diff --git a/query/search.js b/query/search.js index 3f9cdbf5..fe654ab9 100644 --- a/query/search.js +++ b/query/search.js @@ -14,13 +14,13 @@ function generate( params ){ "filter": { "geo_bounding_box": { "center_point": { - "top_left": { - "lat": params.bbox.top_left.lat, - "lon": params.bbox.top_left.lon + "bottom_left": { + "lat": params.bbox.bottom_left.lat, + "lon": params.bbox.bottom_left.lon }, - "bottom_right": { - "lat": params.bbox.bottom_right.lat, - "lon": params.bbox.bottom_right.lon + "top_right": { + "lat": params.bbox.top_right.lat, + "lon": params.bbox.top_right.lon } } } From 5ee018bcf38cf86fbc55aa7b4c1a0cdfafdc5375 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 22 Sep 2014 22:57:28 -0400 Subject: [PATCH 2/2] fixing the tests --- test/unit/query/search.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/query/search.js b/test/unit/query/search.js index 0937178e..3336d379 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -16,11 +16,11 @@ module.exports.tests.query = function(test, common) { input: 'test', size: 10, lat: 29.49136, lon: -82.50622, bbox: { - top_left: { + bottom_left: { lat: 11.51053655297385, lon: -103.16362455862279 }, - bottom_right: { + top_right: { lat: 47.472183447026154, lon: -61.84881544137721 } @@ -38,11 +38,11 @@ module.exports.tests.query = function(test, common) { filter: { geo_bounding_box: { center_point: { - top_left: { + bottom_left: { lat: 11.51053655297385, lon: -103.16362455862279 }, - bottom_right: { + top_right: { lat: 47.472183447026154, lon: -61.84881544137721 }