From e95c2efb54db9683e665a6973cfebc9ebafd7935 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 13 Jul 2015 17:22:37 +0200 Subject: [PATCH 1/7] resolves #139 --- package.json | 12 ++++++------ query/reverse.js | 2 +- test/unit/query/search.js | 14 +------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index fcbfdae7..55f93115 100644 --- a/package.json +++ b/package.json @@ -37,16 +37,16 @@ "express": "^4.8.8", "geojson": "^0.2.1", "geojson-extent": "^0.3.1", - "geopipes-elasticsearch-backend": "0.0.12", + "geopipes-elasticsearch-backend": "^0.2.0", "is-object": "^1.0.1", "markdown": "0.5.0", - "pelias-esclient": "0.0.25", - "pelias-logger": "^0.0.8", - "through2": "0.6.5", + "microtime": "1.4.0", "morgan": "1.5.2", "pelias-config": "^0.1.4", - "microtime": "1.4.0", - "pelias-suggester-pipeline": "2.0.2" + "pelias-esclient": "0.0.25", + "pelias-logger": "^0.0.8", + "pelias-suggester-pipeline": "2.0.2", + "through2": "0.6.5" }, "devDependencies": { "ciao": "^0.3.4", diff --git a/query/reverse.js b/query/reverse.js index 7de12ba8..7759864a 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -9,7 +9,7 @@ function generate( params ){ lon: params.lon }; - var query = queries.distance( centroid, { size: params.size || 1 } ); + var query = queries.distance( centroid, { size: params.size || 1, sort: true } ); query.sort = query.sort.concat( sort( params ) ); if ( params.categories && params.categories.length > 0 ) { diff --git a/test/unit/query/search.js b/test/unit/query/search.js index 7665f876..d4224dde 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -220,19 +220,7 @@ module.exports.tests.query = function(test, common) { } } }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'unit': 'km' - } - } - ].concat(sort.slice(1)), + 'sort': ['_score'].concat(sort.slice(1)), 'size': 10, 'track_scores': true }; From ce611fd9337e4f394aec4ce969a7ac4b1697898d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 13 Jul 2015 17:24:36 +0200 Subject: [PATCH 2/7] increase search radius to 500km --- query/reverse.js | 7 ++++++- test/unit/query/reverse.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/query/reverse.js b/query/reverse.js index 7759864a..fd835e8f 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -9,7 +9,12 @@ function generate( params ){ lon: params.lon }; - var query = queries.distance( centroid, { size: params.size || 1, sort: true } ); + var query = queries.distance( centroid, { + size: params.size || 1, + sort: true, + distance: '500km' + }); + query.sort = query.sort.concat( sort( params ) ); if ( params.categories && params.categories.length > 0 ) { diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index 7c10f52b..851508bc 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -78,7 +78,7 @@ module.exports.tests.query = function(test, common) { 'must': [ { 'geo_distance': { - 'distance': '50km', + 'distance': '500km', 'distance_type': 'plane', 'optimize_bbox': 'indexed', '_cache': true, @@ -139,7 +139,7 @@ module.exports.tests.query = function(test, common) { 'must': [ { 'geo_distance': { - 'distance': '50km', + 'distance': '500km', 'distance_type': 'plane', 'optimize_bbox': 'indexed', '_cache': true, From 42a2c189fcaf7d20ad03cf252e32507e32ca3cd9 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 13 Jul 2015 17:32:28 +0200 Subject: [PATCH 3/7] update travis to use containers --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 82ec939c..4ca5cafc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js script: "npm run unit" node_js: - - "0.10" \ No newline at end of file + - "0.10" +sudo: false \ No newline at end of file From 28e656faa34ae7b48dc2021bbe0a536c30d14843 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 13 Jul 2015 17:34:03 +0200 Subject: [PATCH 4/7] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55f93115..b59a6ffc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pelias-api", "author": "mapzen", - "version": "2.0.0", + "version": "2.1.0", "description": "Pelias API", "homepage": "https://github.com/pelias/api", "license": "MIT", From b51aed512bc6898a086556a5b1c2e4d6e96f89ea Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 13 Jul 2015 17:10:21 -0400 Subject: [PATCH 5/7] adding 408.js --- app.js | 1 + middleware/408.js | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 middleware/408.js diff --git a/app.js b/app.js index 869628de..933b7093 100644 --- a/app.js +++ b/app.js @@ -52,6 +52,7 @@ app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined /** ----------------------- error middleware ----------------------- **/ app.use( require('./middleware/404') ); +app.use( require('./middleware/408') ); app.use( require('./middleware/500') ); module.exports = app; \ No newline at end of file diff --git a/middleware/408.js b/middleware/408.js new file mode 100644 index 00000000..f0edfd59 --- /dev/null +++ b/middleware/408.js @@ -0,0 +1,9 @@ + +// handle time out errors +function middleware(err, req, res, next) { + res.header('Cache-Control','no-cache'); + if( res.statusCode === 408 ){ res.status(408); } + res.json({ error: typeof err === 'string' ? err : 'request time out' }); +} + +module.exports = middleware; \ No newline at end of file From 793182148a96fbbc874e1199696bbe91baba2d30 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 14 Jul 2015 14:01:59 -0400 Subject: [PATCH 6/7] middleware fix --- middleware/408.js | 8 ++++++-- middleware/500.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/middleware/408.js b/middleware/408.js index f0edfd59..fd577fb2 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,8 +2,12 @@ // handle time out errors function middleware(err, req, res, next) { res.header('Cache-Control','no-cache'); - if( res.statusCode === 408 ){ res.status(408); } - res.json({ error: typeof err === 'string' ? err : 'request time out' }); + if( res.statusCode === 408 ){ + res.status(408); + res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' }); + } else { + next(err); + } } module.exports = middleware; \ No newline at end of file diff --git a/middleware/500.js b/middleware/500.js index ecd2ee1d..9f274e23 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -5,7 +5,7 @@ function middleware(err, req, res, next) { logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); res.header('Cache-Control','no-cache'); if( res.statusCode < 400 ){ res.status(500); } - res.json({ error: typeof err === 'string' ? err : 'internal server error' }); + res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' }); } module.exports = middleware; From 1cfa76880b1ba3ca3bffc2eea72fc47d0f1cb5fe Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 14 Jul 2015 14:24:39 -0400 Subject: [PATCH 7/7] check for err message if it contains the words request timeout (because sometimes it comes back as a 500 even though it should be 408) --- middleware/408.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/408.js b/middleware/408.js index fd577fb2..2b2a7b8a 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,7 +2,7 @@ // handle time out errors function middleware(err, req, res, next) { res.header('Cache-Control','no-cache'); - if( res.statusCode === 408 ){ + if( res.statusCode === 408 || (err.message.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' }); } else {