From 02792de2dc6bc6c87c318cf1d3d046f6ffb157b1 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Fri, 25 Sep 2015 14:18:01 -0400 Subject: [PATCH 01/18] added unit tests for verifying valid mapping between sources and layers --- test/unit/helper/type_mapping.js | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 144fadfb..4c22b300 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -39,6 +39,97 @@ module.exports.tests.interfaces = function(test, common) { t.ok(check.hasLength(Object.keys(type_mapping.layer_with_aliases_to_type), 9), 'has correct number of elements'); t.end(); }); + + test('\'osm\' and \'openstreetmap\' sources should only successfully map to \'venue\' and \'address\' layers', function(t) { + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'venue'), ['osmnode', 'osmway']); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'address'), ['osmaddress']); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'locality'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'neighbourhood'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('osm', 'coarse'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'venue'), ['osmnode', 'osmway']); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'address'), ['osmaddress']); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'locality'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'neighbourhood'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openstreetmap', 'coarse'), []); + t.end(); + }); + + test('\'gn\' and \'geonames\' sources should only successfully map to a subset of layers', function(t) { + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'venue'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'address'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'country'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'region'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'county'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'locality'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'neighbourhood'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'coarse'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'venue'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'address'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'country'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'region'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'county'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'locality'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'neighbourhood'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'coarse'), []); + t.end(); + }); + + test('\'oa\' and \'openaddresses\' sources should only successfully map to \'address\' layer', function(t) { + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'venue'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'address'), ['openaddresses']); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'locality'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'neighbourhood'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('oa', 'coarse'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'venue'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'address'), ['openaddresses']); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'locality'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'localadmin'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'neighbourhood'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('openaddresses', 'coarse'), []); + t.end(); + }); + + test('\'qs\' and \'quattroshapes\' sources should only successfully map to \'address\' layer', function(t) { + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'venue'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'address'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'country'), ['admin0']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'region'), ['admin1']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'county'), ['admin2']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'locality'), ['locality']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'localadmin'), ['local_admin']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'neighbourhood'), ['neighborhood']); + t.deepEquals(type_mapping.source_and_layer_to_type('qs', 'coarse'), + ['admin0','admin1','admin2','neighborhood','locality','local_admin']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'venue'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'address'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'country'), ['admin0']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'region'), ['admin1']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'county'), ['admin2']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'locality'), ['locality']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'localadmin'), ['local_admin']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'neighbourhood'), ['neighborhood']); + t.deepEquals(type_mapping.source_and_layer_to_type('quattroshapes', 'coarse'), + ['admin0','admin1','admin2','neighborhood','locality','local_admin']); + t.end(); + }); + }; module.exports.all = function (tape, common) { From 4be987045e6d25d73446044078115c5163303160 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Wed, 30 Sep 2015 15:44:37 -0400 Subject: [PATCH 02/18] updated tests to reflect master type_mapping --- test/unit/helper/type_mapping.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 4c22b300..b44b00a9 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -62,24 +62,24 @@ module.exports.tests.interfaces = function(test, common) { t.end(); }); - test('\'gn\' and \'geonames\' sources should only successfully map to a subset of layers', function(t) { + test('\'gn\' and \'geonames\' sources should only successfully map to \'venue\' layers', function(t) { t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'venue'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'address'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'country'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'region'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'county'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'locality'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'address'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'locality'), []); t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'localadmin'), []); - t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'neighbourhood'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'neighbourhood'), []); t.deepEquals(type_mapping.source_and_layer_to_type('gn', 'coarse'), []); t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'venue'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'address'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'country'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'region'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'county'), ['geoname']); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'locality'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'address'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'country'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'region'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'county'), []); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'locality'), []); t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'localadmin'), []); - t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'neighbourhood'), ['geoname']); + t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'neighbourhood'), []); t.deepEquals(type_mapping.source_and_layer_to_type('geonames', 'coarse'), []); t.end(); }); From ab006054f86ca34dffd4cdd2aceb55293d81836a Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 1 Oct 2015 15:49:58 -0400 Subject: [PATCH 03/18] Fix low hanging fruit in ciao tests Quite a few of our tests simply had old error messages as expectations, or expected output in an array that was correct but in the wrong order. Those are all fixed. --- test/ciao/autocomplete/focus_point_missing_lat.coffee | 4 ++-- test/ciao/autocomplete/focus_point_missing_lon.coffee | 4 ++-- test/ciao/reverse/point_missing_lat.coffee | 4 ++-- test/ciao/reverse/point_missing_lon.coffee | 4 ++-- test/ciao/reverse/sources_multiple.coffee | 2 +- test/ciao/reverse/sources_single.coffee | 2 +- test/ciao/search/boundary_circle_missing_lat.coffee | 4 ++-- test/ciao/search/boundary_circle_missing_lon.coffee | 4 ++-- test/ciao/search/boundary_rect_partially_specified.coffee | 4 ++-- test/ciao/search/focus_point_missing_lat.coffee | 4 ++-- test/ciao/search/focus_point_missing_lon.coffee | 4 ++-- test/ciao/search/sources_multiple.coffee | 2 +- test/ciao/search/sources_single.coffee | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/ciao/autocomplete/focus_point_missing_lat.coffee b/test/ciao/autocomplete/focus_point_missing_lat.coffee index a3da2f8a..300a3bd5 100644 --- a/test/ciao/autocomplete/focus_point_missing_lat.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_missing_lon.coffee b/test/ciao/autocomplete/focus_point_missing_lon.coffee index 8c9a8f48..fc1e507b 100644 --- a/test/ciao/autocomplete/focus_point_missing_lon.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/reverse/point_missing_lat.coffee b/test/ciao/reverse/point_missing_lat.coffee index 649a5db6..7cd2f44a 100644 --- a/test/ciao/reverse/point_missing_lat.coffee +++ b/test/ciao/reverse/point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters point.lat and point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_missing_lon.coffee b/test/ciao/reverse/point_missing_lon.coffee index e28f2a1b..a206726a 100644 --- a/test/ciao/reverse/point_missing_lon.coffee +++ b/test/ciao/reverse/point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters point.lat and point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/sources_multiple.coffee b/test/ciao/reverse/sources_multiple.coffee index 9de6389f..8728109c 100644 --- a/test/ciao/reverse/sources_multiple.coffee +++ b/test/ciao/reverse/sources_multiple.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway","geoname"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway","geoname"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["geoname","osmnode","osmway","osmaddress"] diff --git a/test/ciao/reverse/sources_single.coffee b/test/ciao/reverse/sources_single.coffee index ad4628f4..2c638503 100644 --- a/test/ciao/reverse/sources_single.coffee +++ b/test/ciao/reverse/sources_single.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["osmnode","osmway","osmaddress"] diff --git a/test/ciao/search/boundary_circle_missing_lat.coffee b/test/ciao/search/boundary_circle_missing_lat.coffee index ccc7dcc0..74adb916 100644 --- a/test/ciao/search/boundary_circle_missing_lat.coffee +++ b/test/ciao/search/boundary_circle_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing circle param \'boundary.circle\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.circle.lat and boundary.circle.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -34,4 +34,4 @@ json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/search/boundary_circle_missing_lon.coffee b/test/ciao/search/boundary_circle_missing_lon.coffee index 63a1d794..9e7e314d 100644 --- a/test/ciao/search/boundary_circle_missing_lon.coffee +++ b/test/ciao/search/boundary_circle_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing circle param \'boundary.circle\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.circle.lat and boundary.circle.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -34,4 +34,4 @@ json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/search/boundary_rect_partially_specified.coffee b/test/ciao/search/boundary_rect_partially_specified.coffee index c00e77bc..0c0e72e1 100644 --- a/test/ciao/search/boundary_rect_partially_specified.coffee +++ b/test/ciao/search/boundary_rect_partially_specified.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing rect param \'boundary.rect\' requires all of: \'min_lat\',\'max_lat\',\'min_lon\',\'max_lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.rect.min_lat, boundary.rect.max_lat, boundary.rect.min_lon and boundary.rect.max_lon must all be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -35,4 +35,4 @@ json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.rect.min_lat'] should.not.exist json.geocoding.query['boundary.rect.max_lat'] should.not.exist json.geocoding.query['boundary.rect.min_lon'] -should.not.exist json.geocoding.query['boundary.rect.max_lon'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.rect.max_lon'] diff --git a/test/ciao/search/focus_point_missing_lat.coffee b/test/ciao/search/focus_point_missing_lat.coffee index 0a730f41..6e534133 100644 --- a/test/ciao/search/focus_point_missing_lat.coffee +++ b/test/ciao/search/focus_point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_missing_lon.coffee b/test/ciao/search/focus_point_missing_lon.coffee index e712764c..cf81b267 100644 --- a/test/ciao/search/focus_point_missing_lon.coffee +++ b/test/ciao/search/focus_point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/sources_multiple.coffee b/test/ciao/search/sources_multiple.coffee index fa32183f..a376e5a7 100644 --- a/test/ciao/search/sources_multiple.coffee +++ b/test/ciao/search/sources_multiple.coffee @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway","geoname"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway","geoname"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["geoname","osmnode","osmway","osmaddress"] diff --git a/test/ciao/search/sources_single.coffee b/test/ciao/search/sources_single.coffee index a32ad0a7..3b3e0bf4 100644 --- a/test/ciao/search/sources_single.coffee +++ b/test/ciao/search/sources_single.coffee @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["osmnode","osmway","osmaddress"] From 51858781a9168a56ec2ccdf6a5f2f2d70f85588a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 2 Oct 2015 12:48:56 +0200 Subject: [PATCH 04/18] fix ciao tests --- .../autocomplete/focus_point_missing_lat.coffee | 4 ++-- .../autocomplete/focus_point_missing_lon.coffee | 4 ++-- .../reverse/boundary_circle_invalid_radius.coffee | 15 ++++++++------- .../reverse/boundary_circle_valid_radius.coffee | 15 ++++++++------- test/ciao/reverse/point_missing_lat.coffee | 4 ++-- test/ciao/reverse/point_missing_lon.coffee | 4 ++-- test/ciao/reverse/sources_multiple.coffee | 2 +- test/ciao/reverse/sources_single.coffee | 2 +- .../search/boundary_circle_invalid_radius.coffee | 6 +++--- .../search/boundary_circle_missing_lat.coffee | 4 ++-- .../search/boundary_circle_missing_lon.coffee | 4 ++-- .../boundary_rect_partially_specified.coffee | 4 ++-- test/ciao/search/focus_point_missing_lat.coffee | 4 ++-- test/ciao/search/focus_point_missing_lon.coffee | 4 ++-- test/ciao/search/sources_multiple.coffee | 6 +++--- test/ciao/search/sources_single.coffee | 2 +- 16 files changed, 43 insertions(+), 41 deletions(-) diff --git a/test/ciao/autocomplete/focus_point_missing_lat.coffee b/test/ciao/autocomplete/focus_point_missing_lat.coffee index a3da2f8a..300a3bd5 100644 --- a/test/ciao/autocomplete/focus_point_missing_lat.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_missing_lon.coffee b/test/ciao/autocomplete/focus_point_missing_lon.coffee index 8c9a8f48..fc1e507b 100644 --- a/test/ciao/autocomplete/focus_point_missing_lon.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/reverse/boundary_circle_invalid_radius.coffee b/test/ciao/reverse/boundary_circle_invalid_radius.coffee index 3259f6b2..386ff167 100644 --- a/test/ciao/reverse/boundary_circle_invalid_radius.coffee +++ b/test/ciao/reverse/boundary_circle_invalid_radius.coffee @@ -27,12 +27,13 @@ should.exist json.geocoding.errors json.geocoding.errors.should.eql [ 'missing param \'boundary.circle.radius\'' ] #? expected warnings -should.not.exist json.geocoding.warnings +should.exist json.geocoding.warnings +json.geocoding.warnings.should.eql [ 'boundary.circle is currently unsupported' ] #? inputs -json.geocoding.query['size'].should.eql 10 -json.geocoding.query['point.lat'].should.eql 40.744243 -json.geocoding.query['point.lon'].should.eql -73.990342 -json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 -json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +# json.geocoding.query['size'].should.eql 10 +# json.geocoding.query['point.lat'].should.eql 40.744243 +# json.geocoding.query['point.lon'].should.eql -73.990342 +# json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 +# json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 +# should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/reverse/boundary_circle_valid_radius.coffee b/test/ciao/reverse/boundary_circle_valid_radius.coffee index 1664be63..9279eb70 100644 --- a/test/ciao/reverse/boundary_circle_valid_radius.coffee +++ b/test/ciao/reverse/boundary_circle_valid_radius.coffee @@ -26,12 +26,13 @@ json.features.should.be.instanceof Array should.not.exist json.geocoding.errors #? expected warnings -should.not.exist json.geocoding.warnings +should.exist json.geocoding.warnings +json.geocoding.warnings.should.eql [ 'boundary.circle is currently unsupported' ] #? inputs -json.geocoding.query['size'].should.eql 10 -json.geocoding.query['point.lat'].should.eql 40.744243 -json.geocoding.query['point.lon'].should.eql -73.990342 -json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 -json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 -json.geocoding.query['boundary.circle.radius'].should.eql 999.9 \ No newline at end of file +# json.geocoding.query['size'].should.eql 10 +# json.geocoding.query['point.lat'].should.eql 40.744243 +# json.geocoding.query['point.lon'].should.eql -73.990342 +# json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 +# json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 +# json.geocoding.query['boundary.circle.radius'].should.eql 999.9 diff --git a/test/ciao/reverse/point_missing_lat.coffee b/test/ciao/reverse/point_missing_lat.coffee index 649a5db6..7cd2f44a 100644 --- a/test/ciao/reverse/point_missing_lat.coffee +++ b/test/ciao/reverse/point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters point.lat and point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_missing_lon.coffee b/test/ciao/reverse/point_missing_lon.coffee index e28f2a1b..a206726a 100644 --- a/test/ciao/reverse/point_missing_lon.coffee +++ b/test/ciao/reverse/point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters point.lat and point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/sources_multiple.coffee b/test/ciao/reverse/sources_multiple.coffee index 9de6389f..8728109c 100644 --- a/test/ciao/reverse/sources_multiple.coffee +++ b/test/ciao/reverse/sources_multiple.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway","geoname"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway","geoname"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["geoname","osmnode","osmway","osmaddress"] diff --git a/test/ciao/reverse/sources_single.coffee b/test/ciao/reverse/sources_single.coffee index ad4628f4..2c638503 100644 --- a/test/ciao/reverse/sources_single.coffee +++ b/test/ciao/reverse/sources_single.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["osmnode","osmway","osmaddress"] diff --git a/test/ciao/search/boundary_circle_invalid_radius.coffee b/test/ciao/search/boundary_circle_invalid_radius.coffee index d73b99d2..67c573b6 100644 --- a/test/ciao/search/boundary_circle_invalid_radius.coffee +++ b/test/ciao/search/boundary_circle_invalid_radius.coffee @@ -32,6 +32,6 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 -json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.circle.lat'] +should.not.exist json.geocoding.query['boundary.circle.lon'] +should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/search/boundary_circle_missing_lat.coffee b/test/ciao/search/boundary_circle_missing_lat.coffee index ccc7dcc0..e46b079a 100644 --- a/test/ciao/search/boundary_circle_missing_lat.coffee +++ b/test/ciao/search/boundary_circle_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing circle param \'boundary.circle\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.circle.lat and boundary.circle.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,6 +32,6 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 +json.geocoding.query['boundary.circle.radius'].should.eql 100 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file diff --git a/test/ciao/search/boundary_circle_missing_lon.coffee b/test/ciao/search/boundary_circle_missing_lon.coffee index 63a1d794..45bc0120 100644 --- a/test/ciao/search/boundary_circle_missing_lon.coffee +++ b/test/ciao/search/boundary_circle_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing circle param \'boundary.circle\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.circle.lat and boundary.circle.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,6 +32,6 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 +json.geocoding.query['boundary.circle.radius'].should.eql 100 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file diff --git a/test/ciao/search/boundary_rect_partially_specified.coffee b/test/ciao/search/boundary_rect_partially_specified.coffee index c00e77bc..0c0e72e1 100644 --- a/test/ciao/search/boundary_rect_partially_specified.coffee +++ b/test/ciao/search/boundary_rect_partially_specified.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing rect param \'boundary.rect\' requires all of: \'min_lat\',\'max_lat\',\'min_lon\',\'max_lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters boundary.rect.min_lat, boundary.rect.max_lat, boundary.rect.min_lon and boundary.rect.max_lon must all be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -35,4 +35,4 @@ json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.rect.min_lat'] should.not.exist json.geocoding.query['boundary.rect.max_lat'] should.not.exist json.geocoding.query['boundary.rect.min_lon'] -should.not.exist json.geocoding.query['boundary.rect.max_lon'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.rect.max_lon'] diff --git a/test/ciao/search/focus_point_missing_lat.coffee b/test/ciao/search/focus_point_missing_lat.coffee index 0a730f41..6e534133 100644 --- a/test/ciao/search/focus_point_missing_lat.coffee +++ b/test/ciao/search/focus_point_missing_lat.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_missing_lon.coffee b/test/ciao/search/focus_point_missing_lon.coffee index e712764c..cf81b267 100644 --- a/test/ciao/search/focus_point_missing_lon.coffee +++ b/test/ciao/search/focus_point_missing_lon.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] +json.geocoding.errors.should.eql [ 'parameters focus.point.lat and focus.point.lon must both be specified' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/sources_multiple.coffee b/test/ciao/search/sources_multiple.coffee index fa32183f..fa5a650c 100644 --- a/test/ciao/search/sources_multiple.coffee +++ b/test/ciao/search/sources_multiple.coffee @@ -1,10 +1,10 @@ #> sources filter -path: '/v1/search?text=a&sources=openstreetmap,geonames' +path: "/v1/search?text=a&sources=openstreetmap,geonames" #? 200 ok response.statusCode.should.be.equal 200 -response.should.have.header 'charset', 'utf8' +response.should.have.header "charset", 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' #? valid geocoding block @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway","geoname"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway","geoname"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["geoname","osmnode","osmway","osmaddress"] diff --git a/test/ciao/search/sources_single.coffee b/test/ciao/search/sources_single.coffee index a32ad0a7..3b3e0bf4 100644 --- a/test/ciao/search/sources_single.coffee +++ b/test/ciao/search/sources_single.coffee @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway"] -json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway"] \ No newline at end of file +json.geocoding.query['type'].should.eql ["osmnode","osmway","osmaddress"] From c609ae3ccf1b2986846ce44c58c666645d343c70 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 2 Oct 2015 15:10:24 +0200 Subject: [PATCH 05/18] http friendly status codes. resolves #321 --- app.js | 3 +- controller/place.js | 2 +- controller/search.js | 2 +- middleware/404.js | 2 +- middleware/408.js | 15 -------- middleware/sendJSON.js | 37 +++++++++++++++++-- routes/v1.js | 2 +- sanitiser/sanitizeAll.js | 2 +- .../focus_point_invalid_lat.coffee | 4 +- .../focus_point_invalid_lon.coffee | 4 +- .../focus_point_missing_lat.coffee | 2 +- .../focus_point_missing_lon.coffee | 2 +- test/ciao/autocomplete/no_params.coffee | 4 +- test/ciao/autocomplete/text_invalid.coffee | 4 +- test/ciao/place/missing_id.coffee | 2 +- .../boundary_circle_invalid_radius.coffee | 2 +- .../boundary_country_invalid_alpha2.coffee | 4 +- .../boundary_country_invalid_alpha3.coffee | 4 +- .../boundary_country_invalid_iso3166.coffee | 4 +- .../reverse/duplicate_parameter_name.coffee | 2 +- test/ciao/reverse/layers_invalid.coffee | 2 +- .../reverse/layers_mix_invalid_valid.coffee | 2 +- test/ciao/reverse/non_scalar_parameter.coffee | 2 +- test/ciao/reverse/point_invalid_lat.coffee | 4 +- test/ciao/reverse/point_invalid_lon.coffee | 4 +- test/ciao/reverse/point_missing_lat.coffee | 2 +- test/ciao/reverse/point_missing_lon.coffee | 2 +- test/ciao/reverse/sources_invalid.coffee | 4 +- .../sources_layers_invalid_combo.coffee | 2 +- ...undary_circle_invalid_lat_lon_types.coffee | 4 +- .../boundary_circle_invalid_radius.coffee | 2 +- .../search/boundary_circle_missing_lat.coffee | 2 +- .../search/boundary_circle_missing_lon.coffee | 2 +- .../boundary_country_invalid_alpha2.coffee | 4 +- .../boundary_country_invalid_alpha3.coffee | 4 +- .../boundary_country_invalid_iso3166.coffee | 4 +- .../boundary_rect_partially_specified.coffee | 2 +- .../search/focus_point_invalid_lat.coffee | 4 +- .../search/focus_point_invalid_lon.coffee | 4 +- .../search/focus_point_missing_lat.coffee | 2 +- .../search/focus_point_missing_lon.coffee | 2 +- test/ciao/search/layers_invalid.coffee | 2 +- .../search/layers_mix_invalid_valid.coffee | 2 +- test/ciao/search/no_params.coffee | 4 +- test/ciao/search/sources_invalid.coffee | 4 +- .../sources_layers_invalid_combo.coffee | 2 +- test/ciao/search/text_invalid.coffee | 4 +- test/ciao/search/text_valid.coffee | 2 +- 48 files changed, 99 insertions(+), 84 deletions(-) delete mode 100644 middleware/408.js diff --git a/app.js b/app.js index 241c0920..d05e0365 100644 --- a/app.js +++ b/app.js @@ -26,7 +26,6 @@ v1.addRoutes(app, peliasConfig); /** ----------------------- 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 +module.exports = app; diff --git a/controller/place.js b/controller/place.js index e24be2fc..2a4462cc 100644 --- a/controller/place.js +++ b/controller/place.js @@ -29,7 +29,7 @@ function setup( backend ){ // error handler if( err ){ - req.errors.push( err.message ? err.message : err ); + req.errors.push( err ); } // set response data else { diff --git a/controller/search.js b/controller/search.js index 795ad2c6..93767713 100644 --- a/controller/search.js +++ b/controller/search.js @@ -31,7 +31,7 @@ function setup( backend, query ){ // error handler if( err ){ - req.errors.push( err.message ? err.message : err ); + req.errors.push( err ); } // set response data else { diff --git a/middleware/404.js b/middleware/404.js index 85d81c70..65c25467 100644 --- a/middleware/404.js +++ b/middleware/404.js @@ -5,4 +5,4 @@ function middleware(req, res) { res.status(404).json({ error: 'not found: invalid path' }); } -module.exports = middleware; \ No newline at end of file +module.exports = middleware; diff --git a/middleware/408.js b/middleware/408.js deleted file mode 100644 index 8e57eb28..00000000 --- a/middleware/408.js +++ /dev/null @@ -1,15 +0,0 @@ - -// handle time out errors -function middleware(err, req, res, next) { - res.header('Cache-Control','public'); - var error = (err && err.message) ? err.message : err; - - if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ - res.status(408); - res.json({ error: typeof error === 'string' ? error : 'request timeout' }); - } else { - next(err); - } -} - -module.exports = middleware; \ No newline at end of file diff --git a/middleware/sendJSON.js b/middleware/sendJSON.js index 9ec3e733..94353c6c 100644 --- a/middleware/sendJSON.js +++ b/middleware/sendJSON.js @@ -1,12 +1,43 @@ +var check = require('check-types'); + function sendJSONResponse(req, res, next) { // do nothing if no result data set - if (!res || !res.body) { + if (!res || !check.object(res.body) || !check.object(res.body.geocoding)) { return next(); } + // default status + var statusCode = 200; + + // vary status code whenever an error was reported + var geocoding = res.body.geocoding; + if( check.array( geocoding.errors ) && geocoding.errors.length ){ + + // default status for errors is 400 Bad Request + statusCode = 400; // 400 Bad Request + + // iterate over all reported errors + geocoding.errors.forEach( function( err ){ + // custom status codes for instances of the Error() object. + if( err instanceof Error ){ + // we can extract the error type from the constructor name + switch( err.constructor.name ){ + // elasticsearch errors + // see: https://github.com/elastic/elasticsearch-js/blob/master/src/lib/errors.js + case 'RequestTimeout': statusCode = 408; break; // 408 Request Timeout + case 'NoConnections': statusCode = 502; break; // 502 Bad Gateway + case 'ConnectionFault': statusCode = 502; break; // 502 Bad Gateway + case 'Serialization': statusCode = 500; break; // 500 Internal Server Error + case 'Generic': statusCode = 500; break; // 500 Internal Server Error + default: statusCode = 500; // 500 Internal Server Error + } + } + }); + } + // respond - return res.status(200).json(res.body); + return res.status(statusCode).json(res.body); } -module.exports = sendJSONResponse; \ No newline at end of file +module.exports = sendJSONResponse; diff --git a/routes/v1.js b/routes/v1.js index 352f7c82..397fea21 100644 --- a/routes/v1.js +++ b/routes/v1.js @@ -17,7 +17,7 @@ var middleware = { /** ----------------------- controllers ----------------------- **/ -var controllers = { +var controllers = { mdToHTML: require('../controller/markdownToHtml'), place: require('../controller/place'), search: require('../controller/search'), diff --git a/sanitiser/sanitizeAll.js b/sanitiser/sanitizeAll.js index 1c2dd2af..ac31ddfe 100644 --- a/sanitiser/sanitizeAll.js +++ b/sanitiser/sanitizeAll.js @@ -36,4 +36,4 @@ function sanitize( req, sanitizers, cb ){ } // export function -module.exports = sanitize; \ No newline at end of file +module.exports = sanitize; diff --git a/test/ciao/autocomplete/focus_point_invalid_lat.coffee b/test/ciao/autocomplete/focus_point_invalid_lat.coffee index 37a86593..532bd965 100644 --- a/test/ciao/autocomplete/focus_point_invalid_lat.coffee +++ b/test/ciao/autocomplete/focus_point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=foo&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_invalid_lon.coffee b/test/ciao/autocomplete/focus_point_invalid_lon.coffee index 74779437..04f689d4 100644 --- a/test/ciao/autocomplete/focus_point_invalid_lon.coffee +++ b/test/ciao/autocomplete/focus_point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=40.744243&focus.point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query['focus.point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_missing_lat.coffee b/test/ciao/autocomplete/focus_point_missing_lat.coffee index 300a3bd5..beb17c4d 100644 --- a/test/ciao/autocomplete/focus_point_missing_lat.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/autocomplete/focus_point_missing_lon.coffee b/test/ciao/autocomplete/focus_point_missing_lon.coffee index fc1e507b..c99b23f8 100644 --- a/test/ciao/autocomplete/focus_point_missing_lon.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/autocomplete/no_params.coffee b/test/ciao/autocomplete/no_params.coffee index 5feb9923..216ca9fb 100644 --- a/test/ciao/autocomplete/no_params.coffee +++ b/test/ciao/autocomplete/no_params.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be should.not.exist json.geocoding.warnings #? inputs -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/autocomplete/text_invalid.coffee b/test/ciao/autocomplete/text_invalid.coffee index 8b0e5dc6..3be2faaf 100644 --- a/test/ciao/autocomplete/text_invalid.coffee +++ b/test/ciao/autocomplete/text_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs should.not.exist json.geocoding.query['text'] -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/place/missing_id.coffee b/test/ciao/place/missing_id.coffee index 1fc8ed18..2b525196 100644 --- a/test/ciao/place/missing_id.coffee +++ b/test/ciao/place/missing_id.coffee @@ -3,7 +3,7 @@ path: '/v1/place' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/boundary_circle_invalid_radius.coffee b/test/ciao/reverse/boundary_circle_invalid_radius.coffee index 386ff167..cb257d4e 100644 --- a/test/ciao/reverse/boundary_circle_invalid_radius.coffee +++ b/test/ciao/reverse/boundary_circle_invalid_radius.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243&point.lon=-73.990342&boundary.circle.radius=foo' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/boundary_country_invalid_alpha2.coffee b/test/ciao/reverse/boundary_country_invalid_alpha2.coffee index 5f6e6a13..aced0b50 100644 --- a/test/ciao/reverse/boundary_country_invalid_alpha2.coffee +++ b/test/ciao/reverse/boundary_country_invalid_alpha2.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/boundary_country_invalid_alpha3.coffee b/test/ciao/reverse/boundary_country_invalid_alpha3.coffee index 3ef9e841..0335a77f 100644 --- a/test/ciao/reverse/boundary_country_invalid_alpha3.coffee +++ b/test/ciao/reverse/boundary_country_invalid_alpha3.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/boundary_country_invalid_iso3166.coffee b/test/ciao/reverse/boundary_country_invalid_iso3166.coffee index 05130a9b..cabfbf6e 100644 --- a/test/ciao/reverse/boundary_country_invalid_iso3166.coffee +++ b/test/ciao/reverse/boundary_country_invalid_iso3166.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=FOOBAR' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/duplicate_parameter_name.coffee b/test/ciao/reverse/duplicate_parameter_name.coffee index c38c4da6..701f8e83 100644 --- a/test/ciao/reverse/duplicate_parameter_name.coffee +++ b/test/ciao/reverse/duplicate_parameter_name.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1¶m=value1¶m=value2' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/layers_invalid.coffee b/test/ciao/reverse/layers_invalid.coffee index c4d858fc..354efb02 100644 --- a/test/ciao/reverse/layers_invalid.coffee +++ b/test/ciao/reverse/layers_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&layers=notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/layers_mix_invalid_valid.coffee b/test/ciao/reverse/layers_mix_invalid_valid.coffee index 71a95fa4..a636a26b 100644 --- a/test/ciao/reverse/layers_mix_invalid_valid.coffee +++ b/test/ciao/reverse/layers_mix_invalid_valid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&layers=country,notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/non_scalar_parameter.coffee b/test/ciao/reverse/non_scalar_parameter.coffee index 158c80b2..757761e4 100644 --- a/test/ciao/reverse/non_scalar_parameter.coffee +++ b/test/ciao/reverse/non_scalar_parameter.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1¶meter[idx]=value' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/point_invalid_lat.coffee b/test/ciao/reverse/point_invalid_lat.coffee index 3f085880..52d13b90 100644 --- a/test/ciao/reverse/point_invalid_lat.coffee +++ b/test/ciao/reverse/point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=foo&point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_invalid_lon.coffee b/test/ciao/reverse/point_invalid_lon.coffee index e7e6b436..29c49e01 100644 --- a/test/ciao/reverse/point_invalid_lon.coffee +++ b/test/ciao/reverse/point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243&point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query['point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_missing_lat.coffee b/test/ciao/reverse/point_missing_lat.coffee index 7cd2f44a..f1ffe173 100644 --- a/test/ciao/reverse/point_missing_lat.coffee +++ b/test/ciao/reverse/point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/point_missing_lon.coffee b/test/ciao/reverse/point_missing_lon.coffee index a206726a..b7792b12 100644 --- a/test/ciao/reverse/point_missing_lon.coffee +++ b/test/ciao/reverse/point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/sources_invalid.coffee b/test/ciao/reverse/sources_invalid.coffee index e464cfe4..bdc6c826 100644 --- a/test/ciao/reverse/sources_invalid.coffee +++ b/test/ciao/reverse/sources_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap,notasource' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['types'] -should.not.exist json.geocoding.query['type'] \ No newline at end of file +should.not.exist json.geocoding.query['type'] diff --git a/test/ciao/reverse/sources_layers_invalid_combo.coffee b/test/ciao/reverse/sources_layers_invalid_combo.coffee index b15fcc88..17de70ca 100644 --- a/test/ciao/reverse/sources_layers_invalid_combo.coffee +++ b/test/ciao/reverse/sources_layers_invalid_combo.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&sources=quattroshapes&layers=address' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee b/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee index 0a4ba5ec..2e57214f 100644 --- a/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee +++ b/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=foo&boundary.circle.lon=bar' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -34,4 +34,4 @@ json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/search/boundary_circle_invalid_radius.coffee b/test/ciao/search/boundary_circle_invalid_radius.coffee index 67c573b6..7302d723 100644 --- a/test/ciao/search/boundary_circle_invalid_radius.coffee +++ b/test/ciao/search/boundary_circle_invalid_radius.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.lon=-73.990342&boundary.circle.radius=foo' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_missing_lat.coffee b/test/ciao/search/boundary_circle_missing_lat.coffee index e46b079a..ec0ba9ed 100644 --- a/test/ciao/search/boundary_circle_missing_lat.coffee +++ b/test/ciao/search/boundary_circle_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lon=-73.990342&boundary.circle.radius=100' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_missing_lon.coffee b/test/ciao/search/boundary_circle_missing_lon.coffee index 45bc0120..d873031d 100644 --- a/test/ciao/search/boundary_circle_missing_lon.coffee +++ b/test/ciao/search/boundary_circle_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.radius=100' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_country_invalid_alpha2.coffee b/test/ciao/search/boundary_country_invalid_alpha2.coffee index 06c73b6a..0f28b808 100644 --- a/test/ciao/search/boundary_country_invalid_alpha2.coffee +++ b/test/ciao/search/boundary_country_invalid_alpha2.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=ZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_country_invalid_alpha3.coffee b/test/ciao/search/boundary_country_invalid_alpha3.coffee index bd518281..c317aff2 100644 --- a/test/ciao/search/boundary_country_invalid_alpha3.coffee +++ b/test/ciao/search/boundary_country_invalid_alpha3.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=ZZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_country_invalid_iso3166.coffee b/test/ciao/search/boundary_country_invalid_iso3166.coffee index 9f8c9d6b..3cf6728a 100644 --- a/test/ciao/search/boundary_country_invalid_iso3166.coffee +++ b/test/ciao/search/boundary_country_invalid_iso3166.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=FOOBAR' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_rect_partially_specified.coffee b/test/ciao/search/boundary_rect_partially_specified.coffee index 0c0e72e1..7334620b 100644 --- a/test/ciao/search/boundary_rect_partially_specified.coffee +++ b/test/ciao/search/boundary_rect_partially_specified.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.rect.min_lat=-40.659' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/focus_point_invalid_lat.coffee b/test/ciao/search/focus_point_invalid_lat.coffee index 39df4df6..800d25cc 100644 --- a/test/ciao/search/focus_point_invalid_lat.coffee +++ b/test/ciao/search/focus_point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=foo&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_invalid_lon.coffee b/test/ciao/search/focus_point_invalid_lon.coffee index da69a8fc..8e72e42a 100644 --- a/test/ciao/search/focus_point_invalid_lon.coffee +++ b/test/ciao/search/focus_point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=40.744243&focus.point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query['focus.point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_missing_lat.coffee b/test/ciao/search/focus_point_missing_lat.coffee index 6e534133..f97f638f 100644 --- a/test/ciao/search/focus_point_missing_lat.coffee +++ b/test/ciao/search/focus_point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/focus_point_missing_lon.coffee b/test/ciao/search/focus_point_missing_lon.coffee index cf81b267..2094b7d1 100644 --- a/test/ciao/search/focus_point_missing_lon.coffee +++ b/test/ciao/search/focus_point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/layers_invalid.coffee b/test/ciao/search/layers_invalid.coffee index 3a7c9d38..ec9c58bd 100644 --- a/test/ciao/search/layers_invalid.coffee +++ b/test/ciao/search/layers_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&layers=notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/layers_mix_invalid_valid.coffee b/test/ciao/search/layers_mix_invalid_valid.coffee index c1a53645..fab29ef2 100644 --- a/test/ciao/search/layers_mix_invalid_valid.coffee +++ b/test/ciao/search/layers_mix_invalid_valid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&layers=country,notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/no_params.coffee b/test/ciao/search/no_params.coffee index e374c6aa..e1b192aa 100644 --- a/test/ciao/search/no_params.coffee +++ b/test/ciao/search/no_params.coffee @@ -3,7 +3,7 @@ path: '/v1/search' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be should.not.exist json.geocoding.warnings #? inputs -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/search/sources_invalid.coffee b/test/ciao/search/sources_invalid.coffee index 9f346faf..2114c9c0 100644 --- a/test/ciao/search/sources_invalid.coffee +++ b/test/ciao/search/sources_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&sources=openstreetmap,notasource' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['types'] -should.not.exist json.geocoding.query['type'] \ No newline at end of file +should.not.exist json.geocoding.query['type'] diff --git a/test/ciao/search/sources_layers_invalid_combo.coffee b/test/ciao/search/sources_layers_invalid_combo.coffee index fb01cdf7..c0f84b13 100644 --- a/test/ciao/search/sources_layers_invalid_combo.coffee +++ b/test/ciao/search/sources_layers_invalid_combo.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&sources=quattroshapes&layers=address' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/text_invalid.coffee b/test/ciao/search/text_invalid.coffee index d50f6dea..67fe7da8 100644 --- a/test/ciao/search/text_invalid.coffee +++ b/test/ciao/search/text_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs should.not.exist json.geocoding.query['text'] -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/search/text_valid.coffee b/test/ciao/search/text_valid.coffee index 039fe8f8..e3214d08 100644 --- a/test/ciao/search/text_valid.coffee +++ b/test/ciao/search/text_valid.coffee @@ -30,4 +30,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 From cc9cdfca22b9fd08c90662cc5bf3126afc6434de Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 29 Sep 2015 17:31:33 -0400 Subject: [PATCH 06/18] Add link to GitHub documentation on /v1/ "landing page" Fixes #234 --- public/apiDoc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/apiDoc.md b/public/apiDoc.md index 54579ac3..4e3ce186 100644 --- a/public/apiDoc.md +++ b/public/apiDoc.md @@ -1 +1 @@ -## DETAILED DOCUMENTATION COMING SOON! \ No newline at end of file +## [View our documentation on GitHub](https://github.com/pelias/pelias-doc/blob/master/index.md) From 05a840753daabec23d59cecdc56961fb7125f296 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 6 Oct 2015 17:03:37 -0400 Subject: [PATCH 07/18] Add comment for confidence score function --- middleware/confidenceScore.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index d04e0ab9..68b85c0d 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -82,6 +82,14 @@ function computeConfidenceScore(req, mean, stdev, hit) { return hit; } +/* + * Check for clearly mismatching properties in a result + * zip code and state (admin1) are currently checked if present + * + * @param {object|undefined} text + * @param {object} hit + * @returns {bool} + */ function checkForDealBreakers(req, hit) { if (check.undefined(req.clean.parsed_text)) { return false; From 56591abe97674c97b0b3e7c24349e598a6f14f02 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 7 Oct 2015 11:29:08 +0200 Subject: [PATCH 08/18] remove all references to tiebreaking groovy scripts --- query/search.js | 5 ---- test/unit/fixture/search_linguistic_bbox.js | 4 +-- test/unit/fixture/search_linguistic_focus.js | 4 +-- .../fixture/search_linguistic_focus_bbox.js | 4 +-- .../search_linguistic_focus_null_island.js | 2 +- test/unit/fixture/sort_default.js | 25 ------------------- test/unit/query/search.js | 11 -------- 7 files changed, 7 insertions(+), 48 deletions(-) delete mode 100644 test/unit/fixture/sort_default.js diff --git a/query/search.js b/query/search.js index a3787535..ab13e5e9 100644 --- a/query/search.js +++ b/query/search.js @@ -36,11 +36,6 @@ query.score( peliasQuery.view.admin('neighborhood') ); query.filter( peliasQuery.view.boundary_circle ); query.filter( peliasQuery.view.boundary_rect ); -// groovy scripts used to handle tie-breaking -query.sort( peliasQuery.view.sort_numeric_script('admin_boost') ); -query.sort( peliasQuery.view.sort_numeric_script('popularity') ); -query.sort( peliasQuery.view.sort_numeric_script('population') ); - // -------------------------------- /** diff --git a/test/unit/fixture/search_linguistic_bbox.js b/test/unit/fixture/search_linguistic_bbox.js index 6c98b010..f2059541 100644 --- a/test/unit/fixture/search_linguistic_bbox.js +++ b/test/unit/fixture/search_linguistic_bbox.js @@ -86,7 +86,7 @@ module.exports = { } } }, - 'sort': [ '_sort' ], + 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index 072bca64..888944ca 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -99,7 +99,7 @@ module.exports = { } } }, - 'sort': [ '_sort' ], + 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index e6a04824..0ca37848 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -115,7 +115,7 @@ module.exports = { } } }, - 'sort': [ '_sort' ], + 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index 832aa9f7..54c3cae2 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -99,7 +99,7 @@ module.exports = { } } }, - 'sort': [ '_sort' ], + 'sort': [ '_score' ], 'size': 10, 'track_scores': true }; diff --git a/test/unit/fixture/sort_default.js b/test/unit/fixture/sort_default.js deleted file mode 100644 index fa3edf36..00000000 --- a/test/unit/fixture/sort_default.js +++ /dev/null @@ -1,25 +0,0 @@ - -module.exports = [ - '_score', - { - '_script': { - 'file': 'admin_boost', - 'type': 'number', - 'order': 'desc' - } - }, - { - '_script': { - 'file': 'popularity', - 'type': 'number', - 'order': 'desc' - } - }, - { - '_script': { - 'file': 'population', - 'type': 'number', - 'order': 'desc' - } - } -]; \ No newline at end of file diff --git a/test/unit/query/search.js b/test/unit/query/search.js index e236eaa7..e3db9287 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -10,8 +10,6 @@ module.exports.tests.interface = function(test, common) { }); }; -var sort = require('../fixture/sort_default'); - module.exports.tests.query = function(test, common) { test('valid search + focus + bbox', function(t) { var query = generate({ @@ -26,7 +24,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_bbox'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -44,7 +41,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_bbox'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -58,7 +54,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_only'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -73,7 +68,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -88,7 +82,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_null_island'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -105,7 +98,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_full_address'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -122,7 +114,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_partial_address'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -139,7 +130,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_regions_address'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid search query'); t.end(); @@ -154,7 +144,6 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_boundary_country'); - expected.sort = sort; t.deepEqual(compiled, expected, 'valid boundary.country query'); t.end(); From ea7a177934d9e031bc64afa7d902a4986ac24c0b Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 7 Oct 2015 11:55:22 +0200 Subject: [PATCH 09/18] remove generated ciao docs --- docs/404.md | 63 --------- docs/cors.md | 52 -------- docs/doc/msuccess.md | 97 -------------- docs/doc/success.md | 80 ----------- docs/index.md | 82 ------------ docs/jsonp.md | 50 ------- docs/reverse/success.md | 80 ----------- docs/search/success.md | 233 --------------------------------- docs/suggest/success.md | 111 ---------------- docs/suggest/success_nearby.md | 223 ------------------------------- 10 files changed, 1071 deletions(-) delete mode 100644 docs/404.md delete mode 100644 docs/cors.md delete mode 100644 docs/doc/msuccess.md delete mode 100644 docs/doc/success.md delete mode 100644 docs/index.md delete mode 100644 docs/jsonp.md delete mode 100644 docs/reverse/success.md delete mode 100644 docs/search/success.md delete mode 100644 docs/suggest/success.md delete mode 100644 docs/suggest/success_nearby.md diff --git a/docs/404.md b/docs/404.md deleted file mode 100644 index 917c5ad4..00000000 --- a/docs/404.md +++ /dev/null @@ -1,63 +0,0 @@ -# invalid path - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/notexist" -} -``` - -## Response -```javascript -Status: 404 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=300", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "35", - "etag": "W/\"23-dfdfa185\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "error": "not found: invalid path" -} -``` - -## Tests - -### ✓ not found -```javascript -response.statusCode.should.equal 404 -``` - -### ✓ content-type header correctly set -```javascript -response.should.have.header 'Content-Type','application/json; charset=utf-8' -``` - -### ✓ cache-control header correctly set -```javascript -response.should.have.header 'Cache-Control','public,max-age=300' -``` - -### ✓ should respond in json with server info -```javascript -should.exist json -should.exist json.error -json.error.should.equal 'not found: invalid path' -``` - diff --git a/docs/cors.md b/docs/cors.md deleted file mode 100644 index 17ddda39..00000000 --- a/docs/cors.md +++ /dev/null @@ -1,52 +0,0 @@ -# cross-origin resource sharing - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "50", - "etag": "W/\"32-85536434\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "name": "pelias-api", - "version": { - "number": "0.0.0" - } -} -``` - -## Tests - -### ✓ access control headers correctly set -```javascript -response.should.have.header 'Access-Control-Allow-Origin','*' -response.should.have.header 'Access-Control-Allow-Methods','GET' -response.should.have.header 'Access-Control-Allow-Headers','X-Requested-With,content-type' -response.should.have.header 'Access-Control-Allow-Credentials','true' -``` - diff --git a/docs/doc/msuccess.md b/docs/doc/msuccess.md deleted file mode 100644 index 1f510a42..00000000 --- a/docs/doc/msuccess.md +++ /dev/null @@ -1,97 +0,0 @@ -# valid doc query - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/doc?id=geoname:4221195&id=geoname:4193595" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "555", - "etag": "W/\"22b-dd736629\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.9207, - 34.36094 - ] - }, - "properties": { - "name": "Sanders Grove Cemetery", - "admin0": "United States", - "admin1": "Georgia", - "admin2": "Hart County", - "text": "Sanders Grove Cemetery, Hart County, Georgia" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -83.94213, - 33.32262 - ] - }, - "properties": { - "name": "Etheredge Cemetery", - "admin0": "United States", - "admin1": "Georgia", - "admin2": "Butts County", - "text": "Etheredge Cemetery, Butts County, Georgia" - } - } - ], - "date": 1415292259726 -} -``` - -## Tests - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - diff --git a/docs/doc/success.md b/docs/doc/success.md deleted file mode 100644 index a6dd6c00..00000000 --- a/docs/doc/success.md +++ /dev/null @@ -1,80 +0,0 @@ -# valid doc query - -*Generated: Thu Nov 06 2014 11:44:20 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/doc?id=geoname:4221195" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "311", - "etag": "W/\"137-1644173e\"", - "date": "Thu, 06 Nov 2014 16:44:20 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.9207, - 34.36094 - ] - }, - "properties": { - "name": "Sanders Grove Cemetery", - "admin0": "United States", - "admin1": "Georgia", - "admin2": "Hart County", - "text": "Sanders Grove Cemetery, Hart County, Georgia" - } - } - ], - "date": 1415292260057 -} -``` - -## Tests - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index cde683b5..00000000 --- a/docs/index.md +++ /dev/null @@ -1,82 +0,0 @@ -# api root - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "50", - "etag": "W/\"32-85536434\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "name": "pelias-api", - "version": { - "number": "0.0.0" - } -} -``` - -## Tests - -### ✓ charset header correctly set -```javascript -response.should.have.header 'Charset','utf8' -``` - -### ✓ endpoint available -```javascript -response.statusCode.should.equal 200 -``` - -### ✓ server header correctly set -```javascript -response.should.have.header 'Server' -response.headers.server.should.match /Pelias\/\d{1,2}\.\d{1,2}\.\d{1,2}/ -``` - -### ✓ should respond in json with server info -```javascript -should.exist json -should.exist json.name -should.exist json.version -``` - -### ✓ vanity header correctly set -```javascript -response.should.have.header 'X-Powered-By','mapzen' -``` - -### ✓ content-type header correctly set -```javascript -response.should.have.header 'Content-Type','application/json; charset=utf-8' -``` - -### ✓ cache-control header correctly set -```javascript -response.should.have.header 'Cache-Control','public,max-age=60' -``` - diff --git a/docs/jsonp.md b/docs/jsonp.md deleted file mode 100644 index b8c08577..00000000 --- a/docs/jsonp.md +++ /dev/null @@ -1,50 +0,0 @@ -# jsonp - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/?callback=test" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/javascript; charset=utf-8", - "content-length": "57", - "etag": "W/\"39-b8a2aba1\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```html -test({"name":"pelias-api","version":{"number":"0.0.0"}}); -``` - -## Tests - -### ✓ content-type header correctly set -```javascript -response.should.have.header 'Content-Type','application/javascript; charset=utf-8' -``` - -### ✓ should respond with jsonp -```javascript -should.exist response.body -response.body.substr(0,5).should.equal 'test('; -``` - diff --git a/docs/reverse/success.md b/docs/reverse/success.md deleted file mode 100644 index cb7e84e1..00000000 --- a/docs/reverse/success.md +++ /dev/null @@ -1,80 +0,0 @@ -# valid reverse query - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/reverse?lat=29.49136&lon=-82.50622" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "282", - "etag": "W/\"11a-efcd00c9\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.50622, - 29.49136 - ] - }, - "properties": { - "name": "Adam", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Adam, Alachua County, Florida" - } - } - ], - "date": 1415292259729 -} -``` - -## Tests - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - diff --git a/docs/search/success.md b/docs/search/success.md deleted file mode 100644 index 0b7c675c..00000000 --- a/docs/search/success.md +++ /dev/null @@ -1,233 +0,0 @@ -# valid search query - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/search?text=lake&lat=29.49136&lon=-82.50622" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "2398", - "etag": "W/\"NldeHivz2maJ3rqa73a+2w==\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.5052, - 29.50312 - ] - }, - "properties": { - "name": "Blue Pete Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Blue Pete Lake, Alachua County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.52097, - 29.47185 - ] - }, - "properties": { - "name": "Sawgrass Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Levy County", - "text": "Sawgrass Lake, Levy County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.39141, - 29.4468 - ] - }, - "properties": { - "name": "Johnson Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Marion County", - "text": "Johnson Lake, Marion County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.35435, - 29.49526 - ] - }, - "properties": { - "name": "Ledwith Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Ledwith Lake, Alachua County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.35316, - 29.52469 - ] - }, - "properties": { - "name": "Levy Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Levy Lake, Alachua County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.66311, - 29.54036 - ] - }, - "properties": { - "name": "Fox Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Levy County", - "text": "Fox Lake, Levy County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.40502, - 29.61705 - ] - }, - "properties": { - "name": "Lake Kanapaha", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Lake Kanapaha, Alachua County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.70856, - 29.53293 - ] - }, - "properties": { - "name": "Doorshutter Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Levy County", - "text": "Doorshutter Lake, Levy County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.30215, - 29.52978 - ] - }, - "properties": { - "name": "Wauberg Lake", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Alachua County", - "text": "Wauberg Lake, Alachua County, Florida" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.47914, - 29.30795 - ] - }, - "properties": { - "name": "Lake Stafford", - "admin0": "United States", - "admin1": "Florida", - "admin2": "Levy County", - "text": "Lake Stafford, Levy County, Florida" - } - } - ], - "date": 1415292259730 -} -``` - -## Tests - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - diff --git a/docs/suggest/success.md b/docs/suggest/success.md deleted file mode 100644 index faf2ac79..00000000 --- a/docs/suggest/success.md +++ /dev/null @@ -1,111 +0,0 @@ -# valid suggest query - -*Generated: Thu Nov 06 2014 11:44:19 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/suggest?text=a&lat=0&lon=0" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "571", - "etag": "W/\"23b-5d6e3dd3\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -8.481618, - 43.125692 - ] - }, - "properties": { - "text": "A Coruña", - "score": 14, - "type": "admin1", - "id": "3374:adm1:es:esp:a_coru_a" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - 7.56019, - 5.419786 - ] - }, - "properties": { - "text": "Abia", - "score": 14, - "type": "admin1", - "id": "1775:adm1:ng:nga:abia" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - 33.772337, - 2.826081 - ] - }, - "properties": { - "text": "Abim", - "score": 14, - "type": "admin1", - "id": "2848:adm1:ug:uga:abim" - } - } - ], - "date": 1415292259700 -} -``` - -## Tests - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - diff --git a/docs/suggest/success_nearby.md b/docs/suggest/success_nearby.md deleted file mode 100644 index 047d503e..00000000 --- a/docs/suggest/success_nearby.md +++ /dev/null @@ -1,223 +0,0 @@ -# valid suggest query - -*Generated: Thu Nov 06 2014 11:44:20 GMT-0500 (EST)* -## Request -```javascript -{ - "protocol": "http:", - "host": "localhost", - "method": "GET", - "port": 3100, - "path": "/suggest/nearby?text=a&lat=29.49136&lon=-82.50622" -} -``` - -## Response -```javascript -Status: 200 -{ - "x-powered-by": "mapzen", - "charset": "utf8", - "cache-control": "public,max-age=60", - "server": "Pelias/0.0.0", - "access-control-allow-origin": "*", - "access-control-allow-methods": "GET", - "access-control-allow-headers": "X-Requested-With,content-type", - "access-control-allow-credentials": "true", - "content-type": "application/json; charset=utf-8", - "content-length": "2034", - "etag": "W/\"Do9VJ5hCbynTxDjtm5fNlg==\"", - "date": "Thu, 06 Nov 2014 16:44:19 GMT", - "connection": "close" -} -``` -```javascript -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.05231, - 29.17998 - ] - }, - "properties": { - "text": "Abiding Hope E V Lutheran Church, Marion County, Florida", - "score": 1, - "type": "geoname", - "id": "4145572" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.10231, - 29.21942 - ] - }, - "properties": { - "text": "Abundant Harvest Ministries, Marion County, Florida", - "score": 1, - "type": "geoname", - "id": "4145578" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.50622, - 29.49136 - ] - }, - "properties": { - "text": "Adam, Alachua County, Florida", - "score": 1, - "type": "geoname", - "id": "4145612" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.75374, - 35.17789 - ] - }, - "properties": { - "text": "Adams Branch, Transylvania County, North Carolina", - "score": 1, - "type": "geoname", - "id": "4452189" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.83012, - 29.4783 - ] - }, - "properties": { - "text": "Adamsville Cemetery, Levy County, Florida", - "score": 1, - "type": "geoname", - "id": "4145634" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.01511, - 35.17289 - ] - }, - "properties": { - "text": "Africa School (historical), Spartanburg County, South Carolina", - "score": 1, - "type": "geoname", - "id": "4569065" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.20426, - 29.25192 - ] - }, - "properties": { - "text": "Agape Baptist Church, Marion County, Florida", - "score": 1, - "type": "geoname", - "id": "4145673" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.14954, - 29.19248 - ] - }, - "properties": { - "text": "Agnew Cemetery, Marion County, Florida", - "score": 1, - "type": "geoname", - "id": "4145677" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.75429, - 35.16928 - ] - }, - "properties": { - "text": "Aiken Mountain, Transylvania County, North Carolina", - "score": 1, - "type": "geoname", - "id": "4452268" - } - }, - { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -82.15912, - 29.47877 - ] - }, - "properties": { - "text": "Alachua County Fire Rescue Station 31, Alachua County, Florida", - "score": 1, - "type": "geoname", - "id": "4152402" - } - } - ], - "date": 1415292259785 -} -``` - -## Tests - -### ✓ 200 ok -```javascript -response.statusCode.should.equal 200 -``` - -### ✓ valid response -```javascript -now = new Date().getTime() -should.exist json -should.not.exist json.error -json.date.should.be.within now-5000, now+5000 -``` - -### ✓ valid geojson -```javascript -json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array -``` - From cb679888ff741b1ef6cb32208ea3f3efe34e0696 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 7 Oct 2015 19:56:39 +0200 Subject: [PATCH 10/18] better population and popularity boosting --- package.json | 2 +- query/autocomplete.js | 3 +- query/defaults.js | 16 ++++- query/reverse.js | 2 +- query/search.js | 3 +- .../fixture/autocomplete_linguistic_focus.js | 68 ++++++++++++------- ...tocomplete_linguistic_focus_null_island.js | 66 +++++++++++------- .../fixture/autocomplete_linguistic_only.js | 68 ++++++++++++------- test/unit/fixture/search_boundary_country.js | 66 +++++++++++------- test/unit/fixture/search_full_address.js | 65 +++++++++++------- test/unit/fixture/search_linguistic_bbox.js | 68 ++++++++++++------- test/unit/fixture/search_linguistic_focus.js | 68 ++++++++++++------- .../fixture/search_linguistic_focus_bbox.js | 68 ++++++++++++------- .../search_linguistic_focus_null_island.js | 66 +++++++++++------- test/unit/fixture/search_linguistic_only.js | 68 ++++++++++++------- test/unit/fixture/search_partial_address.js | 68 ++++++++++++------- test/unit/fixture/search_regions_address.js | 68 ++++++++++++------- 17 files changed, 519 insertions(+), 314 deletions(-) diff --git a/package.json b/package.json index abca960e..9cf371b9 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "pelias-config": "^1.0.1", "pelias-esclient": "0.0.25", "pelias-logger": "^0.0.8", - "pelias-query": "2.0.0", + "pelias-query": "4.0.0", "pelias-schema": "1.0.0", "pelias-suggester-pipeline": "2.0.2", "stats-lite": "^1.0.3", diff --git a/query/autocomplete.js b/query/autocomplete.js index 62fb775e..ad64413a 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -14,7 +14,8 @@ query.score( peliasQuery.view.ngrams, 'must' ); // scoring boost query.score( peliasQuery.view.phrase ); query.score( peliasQuery.view.focus( peliasQuery.view.ngrams ) ); -query.score( peliasQuery.view.popularity(['admin0','admin1','admin2']) ); +query.score( peliasQuery.view.popularity( peliasQuery.view.phrase ) ); +query.score( peliasQuery.view.population( peliasQuery.view.phrase ) ); // -------------------------------- diff --git a/query/defaults.js b/query/defaults.js index 83ddb4d9..7b761ae6 100644 --- a/query/defaults.js +++ b/query/defaults.js @@ -8,7 +8,7 @@ module.exports = extend( false, peliasQuery.defaults, { 'track_scores': true, 'centroid:field': 'center_point', - + 'sort:distance:order': 'asc', 'sort:distance:distance_type': 'plane', @@ -79,6 +79,16 @@ module.exports = extend( false, peliasQuery.defaults, { 'admin:neighborhood:analyzer': 'peliasAdmin', 'admin:neighborhood:field': 'neighborhood', - 'admin:neighborhood:boost': 1 + 'admin:neighborhood:boost': 1, + + 'popularity:field': 'popularity', + 'popularity:modifier': 'sqrt', + 'popularity:max_boost': 10000, + 'popularity:weight': 1, + + 'population:field': 'population', + 'population:modifier': 'sqrt', + 'population:max_boost': 2000, + 'population:weight': 1 -}); \ No newline at end of file +}); diff --git a/query/reverse.js b/query/reverse.js index 9401f916..fd84b427 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -44,7 +44,7 @@ function generateQuery( clean ){ // bounding circle // note: the sanitizers will take care of the case - // where point.lan/point.lon are provided in the + // where point.lan/point.lon are provided in the // absense of boundary.circle.lat/boundary.circle.lon if( check.number(clean['boundary.circle.lat']) && check.number(clean['boundary.circle.lon']) && diff --git a/query/search.js b/query/search.js index a3787535..3eeb8798 100644 --- a/query/search.js +++ b/query/search.js @@ -15,7 +15,8 @@ query.score( peliasQuery.view.ngrams, 'must' ); // scoring boost query.score( peliasQuery.view.phrase ); query.score( peliasQuery.view.focus( peliasQuery.view.phrase ) ); -query.score( peliasQuery.view.popularity(['admin0','admin1','admin2']) ); +query.score( peliasQuery.view.popularity( peliasQuery.view.phrase ) ); +query.score( peliasQuery.view.population( peliasQuery.view.phrase ) ); // address components query.score( peliasQuery.view.address('housenumber') ); diff --git a/test/unit/fixture/autocomplete_linguistic_focus.js b/test/unit/fixture/autocomplete_linguistic_focus.js index 2049bf0b..31404731 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus.js +++ b/test/unit/fixture/autocomplete_linguistic_focus.js @@ -50,39 +50,26 @@ module.exports = { 'score_mode': 'avg', 'boost_mode': 'replace' } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -92,6 +79,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } @@ -100,4 +116,4 @@ module.exports = { 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js index 57d4747c..2f46b9b0 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js +++ b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js @@ -50,39 +50,26 @@ module.exports = { 'score_mode': 'avg', 'boost_mode': 'replace' } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -92,6 +79,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } diff --git a/test/unit/fixture/autocomplete_linguistic_only.js b/test/unit/fixture/autocomplete_linguistic_only.js index ac059ef1..65db3fc8 100644 --- a/test/unit/fixture/autocomplete_linguistic_only.js +++ b/test/unit/fixture/autocomplete_linguistic_only.js @@ -23,39 +23,26 @@ module.exports = { 'slop': 2 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -65,6 +52,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } @@ -73,4 +89,4 @@ module.exports = { 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_boundary_country.js b/test/unit/fixture/search_boundary_country.js index a75a8091..76f2c44c 100644 --- a/test/unit/fixture/search_boundary_country.js +++ b/test/unit/fixture/search_boundary_country.js @@ -33,39 +33,26 @@ module.exports = { 'slop': 2 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -75,6 +62,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index aff242b8..0abf05b1 100644 --- a/test/unit/fixture/search_full_address.js +++ b/test/unit/fixture/search_full_address.js @@ -30,35 +30,23 @@ module.exports = { { 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': '123 main st', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -68,6 +56,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': '123 main st', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } },{ 'match': { 'address.number': { @@ -164,4 +181,4 @@ module.exports = { 'size': 10, 'sort': [ '_score' ], 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_bbox.js b/test/unit/fixture/search_linguistic_bbox.js index 6c98b010..738d1b83 100644 --- a/test/unit/fixture/search_linguistic_bbox.js +++ b/test/unit/fixture/search_linguistic_bbox.js @@ -23,39 +23,26 @@ module.exports = { 'slop': 2 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -65,6 +52,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } }, @@ -89,4 +105,4 @@ module.exports = { 'sort': [ '_sort' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index 072bca64..c20ddbf9 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -52,39 +52,26 @@ module.exports = { 'score_mode': 'avg', 'boost_mode': 'replace' } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -94,6 +81,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } @@ -102,4 +118,4 @@ module.exports = { 'sort': [ '_sort' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index e6a04824..92301fa6 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -52,39 +52,26 @@ module.exports = { 'score_mode': 'avg', 'boost_mode': 'replace' } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -94,6 +81,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } }, @@ -118,4 +134,4 @@ module.exports = { 'sort': [ '_sort' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index 832aa9f7..85e6d40a 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -52,39 +52,26 @@ module.exports = { 'score_mode': 'avg', 'boost_mode': 'replace' } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -94,6 +81,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } diff --git a/test/unit/fixture/search_linguistic_only.js b/test/unit/fixture/search_linguistic_only.js index ac059ef1..65db3fc8 100644 --- a/test/unit/fixture/search_linguistic_only.js +++ b/test/unit/fixture/search_linguistic_only.js @@ -23,39 +23,26 @@ module.exports = { 'slop': 2 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -65,6 +52,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'test', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } }] } } @@ -73,4 +89,4 @@ module.exports = { 'sort': [ '_score' ], 'size': 10, 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_partial_address.js b/test/unit/fixture/search_partial_address.js index 94210bf5..d60ebf36 100644 --- a/test/unit/fixture/search_partial_address.js +++ b/test/unit/fixture/search_partial_address.js @@ -26,39 +26,26 @@ module.exports = { 'boost': 1 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': 'soho grand', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -68,6 +55,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': 'soho grand', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } },{ 'match': { 'admin0': { @@ -132,4 +148,4 @@ module.exports = { 'size': 10, 'sort': [ '_score' ], 'track_scores': true -}; \ No newline at end of file +}; diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index 05d4ffe5..17e32ab4 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/test/unit/fixture/search_regions_address.js @@ -26,39 +26,26 @@ module.exports = { 'boost': 1 } } - }, - { + },{ 'function_score': { 'query': { - 'filtered': { - 'filter': { - 'exists': { - 'field': 'popularity' - } + 'match': { + 'phrase.default': { + 'query': '1 water st', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 } } }, - 'max_boost': 2, + 'max_boost': 10000, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { - 'or': [ - { - 'type': { - 'value': 'admin0' - } - }, - { - 'type': { - 'value': 'admin1' - } - }, - { - 'type': { - 'value': 'admin2' - } - } - ] + 'exists': { + 'field': 'popularity' + } }, 'functions': [{ 'field_value_factor': { @@ -68,6 +55,35 @@ module.exports = { 'weight': 1 }] } + },{ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': '1 water st', + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2, + 'boost': 1 + } + } + }, + 'max_boost': 2000, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'filter': { + 'exists': { + 'field': 'population' + } + }, + 'functions': [{ + 'field_value_factor': { + 'modifier': 'sqrt', + 'field': 'population' + }, + 'weight': 1 + }] + } },{ 'match': { 'address.number': { @@ -148,4 +164,4 @@ module.exports = { 'size': 10, 'sort': [ '_score' ], 'track_scores': true -}; \ No newline at end of file +}; From 481a65a4f903959ef3406bf82b4ae3be80cec3f0 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 7 Oct 2015 20:37:10 +0200 Subject: [PATCH 11/18] population twice as important as popularity --- query/defaults.js | 2 +- test/unit/fixture/autocomplete_linguistic_focus.js | 2 +- test/unit/fixture/autocomplete_linguistic_focus_null_island.js | 2 +- test/unit/fixture/autocomplete_linguistic_only.js | 2 +- test/unit/fixture/search_boundary_country.js | 2 +- test/unit/fixture/search_full_address.js | 2 +- test/unit/fixture/search_linguistic_bbox.js | 2 +- test/unit/fixture/search_linguistic_focus.js | 2 +- test/unit/fixture/search_linguistic_focus_bbox.js | 2 +- test/unit/fixture/search_linguistic_focus_null_island.js | 2 +- test/unit/fixture/search_linguistic_only.js | 2 +- test/unit/fixture/search_partial_address.js | 2 +- test/unit/fixture/search_regions_address.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/query/defaults.js b/query/defaults.js index 7b761ae6..ce0a5aea 100644 --- a/query/defaults.js +++ b/query/defaults.js @@ -89,6 +89,6 @@ module.exports = extend( false, peliasQuery.defaults, { 'population:field': 'population', 'population:modifier': 'sqrt', 'population:max_boost': 2000, - 'population:weight': 1 + 'population:weight': 2 }); diff --git a/test/unit/fixture/autocomplete_linguistic_focus.js b/test/unit/fixture/autocomplete_linguistic_focus.js index 31404731..6cd43f52 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus.js +++ b/test/unit/fixture/autocomplete_linguistic_focus.js @@ -105,7 +105,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js index 2f46b9b0..063d0804 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js +++ b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js @@ -105,7 +105,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/autocomplete_linguistic_only.js b/test/unit/fixture/autocomplete_linguistic_only.js index 65db3fc8..e60d84d9 100644 --- a/test/unit/fixture/autocomplete_linguistic_only.js +++ b/test/unit/fixture/autocomplete_linguistic_only.js @@ -78,7 +78,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_boundary_country.js b/test/unit/fixture/search_boundary_country.js index 76f2c44c..ffa6e6bd 100644 --- a/test/unit/fixture/search_boundary_country.js +++ b/test/unit/fixture/search_boundary_country.js @@ -88,7 +88,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index 0abf05b1..205576bc 100644 --- a/test/unit/fixture/search_full_address.js +++ b/test/unit/fixture/search_full_address.js @@ -82,7 +82,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } },{ diff --git a/test/unit/fixture/search_linguistic_bbox.js b/test/unit/fixture/search_linguistic_bbox.js index 738d1b83..8b102f9b 100644 --- a/test/unit/fixture/search_linguistic_bbox.js +++ b/test/unit/fixture/search_linguistic_bbox.js @@ -78,7 +78,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index c20ddbf9..2a0a8deb 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -107,7 +107,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index 92301fa6..3f16ce93 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -107,7 +107,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index 85e6d40a..f734d1ff 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -107,7 +107,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_linguistic_only.js b/test/unit/fixture/search_linguistic_only.js index 65db3fc8..e60d84d9 100644 --- a/test/unit/fixture/search_linguistic_only.js +++ b/test/unit/fixture/search_linguistic_only.js @@ -78,7 +78,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } }] diff --git a/test/unit/fixture/search_partial_address.js b/test/unit/fixture/search_partial_address.js index d60ebf36..72ef8c02 100644 --- a/test/unit/fixture/search_partial_address.js +++ b/test/unit/fixture/search_partial_address.js @@ -81,7 +81,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } },{ diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index 17e32ab4..047a2ffe 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/test/unit/fixture/search_regions_address.js @@ -81,7 +81,7 @@ module.exports = { 'modifier': 'sqrt', 'field': 'population' }, - 'weight': 1 + 'weight': 2 }] } },{ From 2ce249ad30111111a4c625eca59ca853a0908f12 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 06:53:48 +0200 Subject: [PATCH 12/18] adjust balance between population/popularity and focus --- package.json | 2 +- query/defaults.js | 1 + test/unit/fixture/autocomplete_linguistic_focus.js | 3 ++- test/unit/fixture/autocomplete_linguistic_focus_null_island.js | 3 ++- test/unit/fixture/search_linguistic_focus.js | 3 ++- test/unit/fixture/search_linguistic_focus_bbox.js | 3 ++- test/unit/fixture/search_linguistic_focus_null_island.js | 3 ++- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9cf371b9..da77a3df 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "pelias-config": "^1.0.1", "pelias-esclient": "0.0.25", "pelias-logger": "^0.0.8", - "pelias-query": "4.0.0", + "pelias-query": "^5.0.0", "pelias-schema": "1.0.0", "pelias-suggester-pipeline": "2.0.2", "stats-lite": "^1.0.3", diff --git a/query/defaults.js b/query/defaults.js index ce0a5aea..b8ce5ad1 100644 --- a/query/defaults.js +++ b/query/defaults.js @@ -33,6 +33,7 @@ module.exports = extend( false, peliasQuery.defaults, { 'focus:offset': '1km', 'focus:scale': '50km', 'focus:decay': 0.5, + 'focus:weight': 2, 'function_score:score_mode': 'avg', 'function_score:boost_mode': 'replace', diff --git a/test/unit/fixture/autocomplete_linguistic_focus.js b/test/unit/fixture/autocomplete_linguistic_focus.js index 6cd43f52..78f42c7f 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus.js +++ b/test/unit/fixture/autocomplete_linguistic_focus.js @@ -45,7 +45,8 @@ module.exports = { 'scale': '50km', 'decay': 0.5 } - } + }, + 'weight': 2 }], 'score_mode': 'avg', 'boost_mode': 'replace' diff --git a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js index 063d0804..c12995f2 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js +++ b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js @@ -45,7 +45,8 @@ module.exports = { 'scale': '50km', 'decay': 0.5 } - } + }, + 'weight': 2 }], 'score_mode': 'avg', 'boost_mode': 'replace' diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index 2a0a8deb..59227c5c 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -47,7 +47,8 @@ module.exports = { 'scale': '50km', 'decay': 0.5 } - } + }, + 'weight': 2 }], 'score_mode': 'avg', 'boost_mode': 'replace' diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index 3f16ce93..4c2fadb9 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -47,7 +47,8 @@ module.exports = { 'scale': '50km', 'decay': 0.5 } - } + }, + 'weight': 2 }], 'score_mode': 'avg', 'boost_mode': 'replace' diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index f734d1ff..4290cfed 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -47,7 +47,8 @@ module.exports = { 'scale': '50km', 'decay': 0.5 } - } + }, + 'weight': 2 }], 'score_mode': 'avg', 'boost_mode': 'replace' From 8ceac4cbb0001dfdc93ddd7cb16183c54e123062 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 07:40:08 +0200 Subject: [PATCH 13/18] change modifier function from sqrt() to log1p() and adjust max_boost --- query/defaults.js | 8 ++++---- test/unit/fixture/autocomplete_linguistic_focus.js | 8 ++++---- .../fixture/autocomplete_linguistic_focus_null_island.js | 8 ++++---- test/unit/fixture/autocomplete_linguistic_only.js | 8 ++++---- test/unit/fixture/search_boundary_country.js | 8 ++++---- test/unit/fixture/search_full_address.js | 8 ++++---- test/unit/fixture/search_linguistic_bbox.js | 8 ++++---- test/unit/fixture/search_linguistic_focus.js | 8 ++++---- test/unit/fixture/search_linguistic_focus_bbox.js | 8 ++++---- test/unit/fixture/search_linguistic_focus_null_island.js | 8 ++++---- test/unit/fixture/search_linguistic_only.js | 8 ++++---- test/unit/fixture/search_partial_address.js | 8 ++++---- test/unit/fixture/search_regions_address.js | 8 ++++---- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/query/defaults.js b/query/defaults.js index b8ce5ad1..b61e84ac 100644 --- a/query/defaults.js +++ b/query/defaults.js @@ -83,13 +83,13 @@ module.exports = extend( false, peliasQuery.defaults, { 'admin:neighborhood:boost': 1, 'popularity:field': 'popularity', - 'popularity:modifier': 'sqrt', - 'popularity:max_boost': 10000, + 'popularity:modifier': 'log1p', + 'popularity:max_boost': 20, 'popularity:weight': 1, 'population:field': 'population', - 'population:modifier': 'sqrt', - 'population:max_boost': 2000, + 'population:modifier': 'log1p', + 'population:max_boost': 20, 'population:weight': 2 }); diff --git a/test/unit/fixture/autocomplete_linguistic_focus.js b/test/unit/fixture/autocomplete_linguistic_focus.js index 78f42c7f..8d0e9914 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus.js +++ b/test/unit/fixture/autocomplete_linguistic_focus.js @@ -64,7 +64,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -74,7 +74,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -93,7 +93,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -103,7 +103,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js index c12995f2..8300b026 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js +++ b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js @@ -64,7 +64,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -74,7 +74,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -93,7 +93,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -103,7 +103,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/autocomplete_linguistic_only.js b/test/unit/fixture/autocomplete_linguistic_only.js index e60d84d9..53ece28e 100644 --- a/test/unit/fixture/autocomplete_linguistic_only.js +++ b/test/unit/fixture/autocomplete_linguistic_only.js @@ -36,7 +36,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -46,7 +46,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -65,7 +65,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -75,7 +75,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_boundary_country.js b/test/unit/fixture/search_boundary_country.js index ffa6e6bd..3e6f83bc 100644 --- a/test/unit/fixture/search_boundary_country.js +++ b/test/unit/fixture/search_boundary_country.js @@ -46,7 +46,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -56,7 +56,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -75,7 +75,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -85,7 +85,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index 205576bc..93572705 100644 --- a/test/unit/fixture/search_full_address.js +++ b/test/unit/fixture/search_full_address.js @@ -40,7 +40,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -50,7 +50,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -69,7 +69,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -79,7 +79,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_linguistic_bbox.js b/test/unit/fixture/search_linguistic_bbox.js index 8b102f9b..6e6676d5 100644 --- a/test/unit/fixture/search_linguistic_bbox.js +++ b/test/unit/fixture/search_linguistic_bbox.js @@ -36,7 +36,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -46,7 +46,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -65,7 +65,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -75,7 +75,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index 59227c5c..36cb2912 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -66,7 +66,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -76,7 +76,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -95,7 +95,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -105,7 +105,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index 4c2fadb9..4932d56b 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -66,7 +66,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -76,7 +76,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -95,7 +95,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -105,7 +105,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index 4290cfed..04116c55 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -66,7 +66,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -76,7 +76,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -95,7 +95,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -105,7 +105,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_linguistic_only.js b/test/unit/fixture/search_linguistic_only.js index e60d84d9..53ece28e 100644 --- a/test/unit/fixture/search_linguistic_only.js +++ b/test/unit/fixture/search_linguistic_only.js @@ -36,7 +36,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -46,7 +46,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -65,7 +65,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -75,7 +75,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_partial_address.js b/test/unit/fixture/search_partial_address.js index 72ef8c02..6e0fbd5b 100644 --- a/test/unit/fixture/search_partial_address.js +++ b/test/unit/fixture/search_partial_address.js @@ -39,7 +39,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -49,7 +49,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -68,7 +68,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -78,7 +78,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index 047a2ffe..cc04943b 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/test/unit/fixture/search_regions_address.js @@ -39,7 +39,7 @@ module.exports = { } } }, - 'max_boost': 10000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -49,7 +49,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'popularity' }, 'weight': 1 @@ -68,7 +68,7 @@ module.exports = { } } }, - 'max_boost': 2000, + 'max_boost': 20, 'score_mode': 'first', 'boost_mode': 'replace', 'filter': { @@ -78,7 +78,7 @@ module.exports = { }, 'functions': [{ 'field_value_factor': { - 'modifier': 'sqrt', + 'modifier': 'log1p', 'field': 'population' }, 'weight': 2 From b5b8647f0c849c9f7f3ac57cdf2759c9317153aa Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 10:47:45 +0200 Subject: [PATCH 14/18] more label improvements --- helper/labelSchema.json | 10 ++-- test/unit/helper/labelGenerator.js | 77 +++++++++++++++++++++++++++++- test/unit/helper/labelSchema.js | 12 ++--- 3 files changed, 89 insertions(+), 10 deletions(-) diff --git a/helper/labelSchema.json b/helper/labelSchema.json index 49c96017..4b555790 100644 --- a/helper/labelSchema.json +++ b/helper/labelSchema.json @@ -11,8 +11,12 @@ "local": ["neighbourhood", "region", "county", "localadmin", "locality"], "regional": ["county","country","region"] }, + "SWE": { + "local": ["neighbourhood", "region", "county", "localadmin", "locality"], + "regional": ["country"] + }, "default": { - "local": ["localadmin", "locality", "neighbourhood", "county"], - "regional": ["region_a", "region", "country"] + "local": ["localadmin", "locality", "neighbourhood", "county", "region"], + "regional": ["country"] } -} \ No newline at end of file +} diff --git a/test/unit/helper/labelGenerator.js b/test/unit/helper/labelGenerator.js index e1bf0da3..e295c160 100644 --- a/test/unit/helper/labelGenerator.js +++ b/test/unit/helper/labelGenerator.js @@ -92,6 +92,22 @@ module.exports.tests.west_bengal = function(test, common) { }); }; +// IND city +module.exports.tests.bangalore = function(test, common) { + test('bangalore', function(t) { + var doc = { + 'name': { 'default': 'Bangalore' }, + 'country_a': 'IND', + 'country': 'India', + 'region': 'Karnataka', + 'county': 'Bangalore', + 'locality': 'Bangalore' + }; + t.equal(generator(doc),'Bangalore, Karnataka, India'); + t.end(); + }); +}; + // SGP region module.exports.tests.north_west_singapore = function(test, common) { test('north west singapore', function(t) { @@ -134,6 +150,37 @@ module.exports.tests.madrid = function(test, common) { }); }; +// SWE city +module.exports.tests.skane1 = function(test, common) { + test('skåne 1', function(t) { + var doc = { + 'name': { 'default': 'Malmö' }, + 'country_a': 'SWE', + 'country': 'Sweden', + 'region': 'Skåne', + 'county': 'Malmö' + }; + t.equal(generator(doc),'Malmö, Skåne, Sweden'); + t.end(); + }); +}; + +// SWE city +module.exports.tests.skane2 = function(test, common) { + test('skåne 2', function(t) { + var doc = { + 'name': { 'default': 'Malmö' }, + 'country_a': 'SWE', + 'country': 'Sweden', + 'region': 'Skåne', + 'county': 'Malmö', + 'locality': 'Malmö' + }; + t.equal(generator(doc),'Malmö, Skåne, Sweden'); + t.end(); + }); +}; + // GBR street address module.exports.tests.one_main_street_uk = function(test, common) { test('one main street uk', function(t) { @@ -201,6 +248,34 @@ module.exports.tests.new_zealand = function(test, common) { }); }; +// GBR country +module.exports.tests.wales = function(test, common) { + test('wales', function(t) { + var doc = { + 'name': { 'default': 'Wales' }, + 'country_a': 'GBR', + 'country': 'United Kingdom', + 'region': 'Wales' + }; + t.equal(generator(doc),'Wales, United Kingdom'); + t.end(); + }); +}; + +// IRL country +module.exports.tests.republic_of_ireland = function(test, common) { + test('northern ireland', function(t) { + var doc = { + 'name': { 'default': 'Ireland' }, + 'country_a': 'IRL', + 'country': 'Ireland' + }; + // !! this is not part of the UK !! + t.equal(generator(doc),'Ireland'); + t.end(); + }); +}; + // SGP venue module.exports.tests.singapore_mcdonalds = function(test, common) { test('singapore_mcdonalds', function(t) { @@ -225,4 +300,4 @@ module.exports.all = function (tape, common) { for( var testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } -}; \ No newline at end of file +}; diff --git a/test/unit/helper/labelSchema.js b/test/unit/helper/labelSchema.js index f85c43aa..dcc3cdfa 100644 --- a/test/unit/helper/labelSchema.js +++ b/test/unit/helper/labelSchema.js @@ -15,16 +15,16 @@ module.exports.tests.interface = function(test, common) { module.exports.tests.valid = function(test, common) { var valid_keys = ['localadmin', 'locality', 'neighbourhood', 'county', 'region_a', 'region', 'country']; var default_schema = { - local: ['localadmin', 'locality', 'neighbourhood', 'county'], - regional: ['region_a', 'region', 'country'] + local: ['localadmin', 'locality', 'neighbourhood', 'county', 'region'], + regional: ['country'] }; var isValid = function(keys, schema) { test('valid key/object (' + keys + ')' , function(t) { - if (keys === 'default') { + if (keys === 'default') { t.deepEqual(schema, default_schema, 'valid default schema'); } else { - t.equal(alpha3.hasOwnProperty(keys), true, 'valid key'); + t.equal(alpha3.hasOwnProperty(keys), true, 'valid key'); } t.equal(typeof schema, 'object', 'valid object'); t.notEqual(Object.getOwnPropertyNames(schema).length, 0, 'object not empty'); @@ -39,7 +39,7 @@ module.exports.tests.valid = function(test, common) { }); }; - for (var keys in schemas) { + for (var keys in schemas) { isValid(keys, schemas[keys]); } }; @@ -53,4 +53,4 @@ module.exports.all = function (tape, common) { for( var testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } -}; \ No newline at end of file +}; From 5cc432ae50d4b3e57438f77b5ecf8c7de067eaa3 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 10:55:25 +0200 Subject: [PATCH 15/18] more indian test cases --- test/unit/helper/labelGenerator.js | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/unit/helper/labelGenerator.js b/test/unit/helper/labelGenerator.js index e295c160..6a66a86b 100644 --- a/test/unit/helper/labelGenerator.js +++ b/test/unit/helper/labelGenerator.js @@ -108,6 +108,37 @@ module.exports.tests.bangalore = function(test, common) { }); }; +// IND region of city +module.exports.tests.sarjapur = function(test, common) { + test('Sarjapur', function(t) { + var doc = { + 'name': { 'default': 'Sarjapur' }, + 'country_a': 'IND', + 'country': 'India', + 'region': 'Karnataka' + }; + t.equal(generator(doc),'Sarjapur, Karnataka, India'); + t.end(); + }); +}; + +// IND region of city 2 +module.exports.tests.bengaluru_east = function(test, common) { + test('Bengaluru East', function(t) { + var doc = { + 'name': { 'default': 'Bengaluru East' }, + 'country_a': 'IND', + 'country': 'India', + 'region': 'Karnataka', + 'county': 'Bangalore', + 'locality': 'Bangalore', + 'neighbourhood': 'Fraser Town' + }; + t.equal(generator(doc),'Bengaluru East, Bangalore, India'); + t.end(); + }); +}; + // SGP region module.exports.tests.north_west_singapore = function(test, common) { test('north west singapore', function(t) { From 7cf8638795c98b2b2cc86f925cf0521edd8933a7 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 11:03:23 +0200 Subject: [PATCH 16/18] more australian and thai test cases --- test/unit/helper/labelGenerator.js | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/unit/helper/labelGenerator.js b/test/unit/helper/labelGenerator.js index 6a66a86b..1e930d62 100644 --- a/test/unit/helper/labelGenerator.js +++ b/test/unit/helper/labelGenerator.js @@ -139,6 +139,22 @@ module.exports.tests.bengaluru_east = function(test, common) { }); }; +// AUS area +// https://en.wikipedia.org/wiki/Shire_of_Wellington +module.exports.tests.wellington_victoria = function(test, common) { + test('Wellington, Victoria, Australia', function(t) { + var doc = { + 'name': { 'default': 'Wellington' }, + 'country_a': 'AUS', + 'country': 'Australia', + 'region': 'Victoria', + 'county': 'Wellington' + }; + t.equal(generator(doc),'Wellington, Victoria, Australia'); + t.end(); + }); +}; + // SGP region module.exports.tests.north_west_singapore = function(test, common) { test('north west singapore', function(t) { @@ -322,6 +338,34 @@ module.exports.tests.singapore_mcdonalds = function(test, common) { }); }; +// THA province +module.exports.tests.krabi_province = function(test, common) { + test('Krabi Provence', function(t) { + var doc = { + 'name': { 'default': 'Krabi' }, + 'country_a': 'THA', + 'country': 'Thailand', + 'region': 'Krabi' + }; + t.equal(generator(doc),'Krabi, Thailand'); + t.end(); + }); +}; + +// THA island +module.exports.tests.koh_lanta = function(test, common) { + test('Koh Lanta', function(t) { + var doc = { + 'name': { 'default': 'Ko Lanta' }, + 'country_a': 'THA', + 'country': 'Thailand', + 'region': 'Krabi' + }; + t.equal(generator(doc),'Ko Lanta, Krabi, Thailand'); + t.end(); + }); +}; + module.exports.all = function (tape, common) { function test(name, testFunction) { From d93f9c180368a38b009dccba5c2e3f7eadb97483 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 12:16:46 +0200 Subject: [PATCH 17/18] more new zealand test cases --- test/unit/helper/labelGenerator.js | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/unit/helper/labelGenerator.js b/test/unit/helper/labelGenerator.js index 1e930d62..a0fea199 100644 --- a/test/unit/helper/labelGenerator.js +++ b/test/unit/helper/labelGenerator.js @@ -366,6 +366,53 @@ module.exports.tests.koh_lanta = function(test, common) { }); }; +// NZD cafe +module.exports.tests.black_dog_cafe = function(test, common) { + test('Black Dog Cafe', function(t) { + var doc = { + 'name': { 'default': 'Black Dog Cafe' }, + 'country_a': 'NZL', + 'country': 'New Zealand', + 'region': 'Auckland Region', + 'county': 'Auckland' + }; + t.equal(generator(doc),'Black Dog Cafe, Auckland, New Zealand'); + t.end(); + }); +}; + +// NZD cafe 2 +module.exports.tests.beach_bablyon = function(test, common) { + test('Beach Bablyon', function(t) { + var doc = { + 'name': { 'default': 'Beach Bablyon' }, + 'country_a': 'NZL', + 'country': 'New Zealand', + 'region': 'Wellington Region', + 'county': 'Wellington City', + 'locality': 'Wellington', + 'neighbourhood': 'Oriental Bay' + }; + t.equal(generator(doc),'Beach Bablyon, Wellington, New Zealand'); + t.end(); + }); +}; + +// NZD tourism +module.exports.tests.waiotapu = function(test, common) { + test('Waiotapu', function(t) { + var doc = { + 'name': { 'default': 'Waiotapu' }, + 'country_a': 'NZL', + 'country': 'New Zealand', + 'region': 'Bay of Plenty', + 'county': 'Rotorua District' + }; + t.equal(generator(doc),'Waiotapu, Rotorua District, New Zealand'); + t.end(); + }); +}; + module.exports.all = function (tape, common) { function test(name, testFunction) { From 85a51bc48aa9707a2751b68597e90859e086cb45 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Oct 2015 12:31:11 +0200 Subject: [PATCH 18/18] more usa test cases --- test/unit/helper/labelGenerator.js | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/unit/helper/labelGenerator.js b/test/unit/helper/labelGenerator.js index a0fea199..9a382397 100644 --- a/test/unit/helper/labelGenerator.js +++ b/test/unit/helper/labelGenerator.js @@ -49,6 +49,45 @@ module.exports.tests.nyc_office = function(test, common) { }); }; +// USA NYC eatery +module.exports.tests.nyc_bakery = function(test, common) { + test('New York Bakery', function(t) { + var doc = { + 'name': { 'default': 'New York Bakery' }, + 'housenumber': '51 W', + 'street': '29th', + 'country_a': 'USA', + 'country': 'United States', + 'region': 'New York', + 'region_a': 'NY', + 'county': 'New York County', + 'localadmin': 'Manhattan', + 'locality': 'New York', + 'neighbourhood': 'Koreatown' + }; + t.equal(generator(doc),'New York Bakery, Manhattan, NY'); + t.end(); + }); +}; + +// USA SFC building +module.exports.tests.ferry_building = function(test, common) { + test('Ferry Building', function(t) { + var doc = { + 'name': { 'default': 'Ferry Building' }, + 'country_a': 'USA', + 'country': 'United States', + 'region': 'California', + 'region_a': 'CA', + 'county': 'San Francisco County', + 'locality': 'San Francisco', + 'neighbourhood': 'Financial District' + }; + t.equal(generator(doc),'Ferry Building, San Francisco, CA'); + t.end(); + }); +}; + // AUS state module.exports.tests.new_south_wales = function(test, common) { test('new south wales', function(t) {