From 21b6e8de139339322f672e2f0354897d8b5aec0d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 5 Jul 2017 17:31:59 +0000 Subject: [PATCH 01/20] chore(package): update pelias-mock-logger to version 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 404879c1..0e1a9ceb 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "jshint": "^2.5.6", "npm-check": "git://github.com/orangejulius/npm-check.git#disable-update-check", "nsp": "^2.2.0", - "pelias-mock-logger": "1.1.0", + "pelias-mock-logger": "1.1.1", "precommit-hook": "^3.0.0", "proxyquire": "^1.7.10", "semantic-release": "^6.3.2", From c7eb747354a4ffcea6b2604b6e86debb887eb5e6 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 6 Jul 2017 15:30:17 +0000 Subject: [PATCH 02/20] fix(package): update pelias-model to version 4.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e1a9ceb..d60c0b42 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.1.2", - "pelias-model": "4.8.1", + "pelias-model": "4.9.0", "pelias-query": "8.15.0", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.8.3", From 4271f574abea1bbbdfc01aae17f2825eb52ed3c8 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Thu, 6 Jul 2017 13:06:01 -0400 Subject: [PATCH 03/20] updated tests for pelias-model 4.9.0 changes --- test/unit/controller/placeholder.js | 51 ++++++++++------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/test/unit/controller/placeholder.js b/test/unit/controller/placeholder.js index ab64e4c5..74118c8f 100644 --- a/test/unit/controller/placeholder.js +++ b/test/unit/controller/placeholder.js @@ -287,8 +287,7 @@ module.exports.tests.success = (test, common) => { 'default': 'name 3' }, population: 4321, - popularity: 8765, - parent: { } + popularity: 8765 } ] }; @@ -352,8 +351,7 @@ module.exports.tests.success = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -413,8 +411,7 @@ module.exports.tests.success = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -472,8 +469,7 @@ module.exports.tests.success = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -538,8 +534,7 @@ module.exports.tests.success = (test, common) => { }, phrase: { 'default': 'name 2' - }, - parent: { } + } } ] }; @@ -608,8 +603,7 @@ module.exports.tests.success = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -782,8 +776,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } }, { _id: '10', @@ -800,8 +793,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 10' - }, - parent: { } + } } ] }; @@ -968,8 +960,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } }, { _id: '10', @@ -986,8 +977,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 10' - }, - parent: { } + } } ] }; @@ -1107,8 +1097,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } }, { _id: '3', @@ -1125,8 +1114,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 3' - }, - parent: { } + } }, { _id: '5', @@ -1143,8 +1131,7 @@ module.exports.tests.result_filtering = (test, common) => { }, phrase: { 'default': 'name 5' - }, - parent: { } + } } ] }; @@ -1567,8 +1554,7 @@ module.exports.tests.geometry_errors = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: {} + } } ] }; @@ -1628,8 +1614,7 @@ module.exports.tests.centroid_errors = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -1689,8 +1674,7 @@ module.exports.tests.centroid_errors = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; @@ -1763,8 +1747,7 @@ module.exports.tests.boundingbox_errors = (test, common) => { }, phrase: { 'default': 'name 1' - }, - parent: { } + } } ] }; From d68ae32325f1cfe106ebe7eb3f985e62a26d9d47 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 6 Jul 2017 18:23:12 +0000 Subject: [PATCH 04/20] fix(package): update pelias-query to version 8.16.1 Closes #844 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d60c0b42..2a5cbe2e 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.1.2", "pelias-model": "4.9.0", - "pelias-query": "8.15.0", + "pelias-query": "8.16.1", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.8.3", "predicates": "^1.0.1", From 35c7c86492f2d7d01a70eb96392ef2890368d851 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 6 Jul 2017 15:32:26 -0400 Subject: [PATCH 05/20] Update fixtures for Elasticsearch 5 queries These queries use [bool](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html) queries instead of the deprecated `filtered` queries, and also set `minimum_should_match` to 1, which was apparently implied previously. Connects https://github.com/pelias/api/issues/762 Connects https://github.com/pelias/api/pull/844 Connects https://github.com/pelias/api/pull/855 Connects https://github.com/pelias/pelias/issues/461 --- test/unit/fixture/search_boundary_country.js | 41 +- test/unit/fixture/search_fallback.js | 1594 ++++++++-------- .../search_fallback_postalcode_only.js | 50 +- test/unit/fixture/search_linguistic_bbox.js | 41 +- test/unit/fixture/search_linguistic_focus.js | 41 +- .../fixture/search_linguistic_focus_bbox.js | 41 +- .../search_linguistic_focus_null_island.js | 41 +- test/unit/fixture/search_linguistic_only.js | 41 +- .../fixture/search_linguistic_viewport.js | 41 +- ...search_linguistic_viewport_min_diagonal.js | 41 +- .../fixture/search_with_category_filtering.js | 41 +- .../fixture/search_with_source_filtering.js | 41 +- .../boundary_country.json | 11 +- .../structured_geocoding/fallback.json | 1596 ++++++++--------- .../structured_geocoding/linguistic_bbox.json | 11 +- .../linguistic_focus.json | 11 +- .../linguistic_focus_bbox.json | 9 +- .../linguistic_focus_null_island.json | 11 +- .../structured_geocoding/linguistic_only.json | 11 +- .../linguistic_viewport.json | 11 +- .../linguistic_viewport_min_diagonal.json | 11 +- .../structured_geocoding/postalcode_only.js | 50 +- .../with_source_filtering.json | 12 +- 23 files changed, 1855 insertions(+), 1943 deletions(-) diff --git a/test/unit/fixture/search_boundary_country.js b/test/unit/fixture/search_boundary_country.js index ee6427a0..31cad683 100644 --- a/test/unit/fixture/search_boundary_country.js +++ b/test/unit/fixture/search_boundary_country.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_fallback.js b/test/unit/fixture/search_fallback.js index 3835cadb..3725dff1 100644 --- a/test/unit/fixture/search_fallback.js +++ b/test/unit/fixture/search_fallback.js @@ -2,837 +2,829 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.venue', - 'must': [ - { - 'multi_match': { - 'query': 'query value', - 'type': 'phrase', - 'fields': [ - 'phrase.default' - ] - } - }, - { - 'multi_match': { - 'query': 'neighbourhood value', - 'type': 'phrase', - 'fields': [ - 'parent.neighbourhood', - 'parent.neighbourhood_a' - ] - } - }, - { - 'multi_match': { - 'query': 'borough value', - 'type': 'phrase', - 'fields': [ - 'parent.borough', - 'parent.borough_a' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'venue' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.venue', + 'must': [ + { + 'multi_match': { + 'query': 'query value', + 'type': 'phrase', + 'fields': [ + 'phrase.default' + ] } + }, + { + 'multi_match': { + 'query': 'neighbourhood value', + 'type': 'phrase', + 'fields': [ + 'parent.neighbourhood', + 'parent.neighbourhood_a' + ] + } + }, + { + 'multi_match': { + 'query': 'borough value', + 'type': 'phrase', + 'fields': [ + 'parent.borough', + 'parent.borough_a' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'venue' } - }, - { - 'bool': { - '_name': 'fallback.address', - 'boost': 10, - 'must': [ - { - 'match_phrase': { - 'address_parts.number': 'number value' - } - }, - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - }, - { - 'multi_match': { - 'query': 'neighbourhood value', - 'type': 'phrase', - 'fields': [ - 'parent.neighbourhood', - 'parent.neighbourhood_a' - ] - } - }, - { - 'multi_match': { - 'query': 'borough value', - 'type': 'phrase', - 'fields': [ - 'parent.borough', - 'parent.borough_a' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'should': [ - { - 'match_phrase': { - 'address_parts.zip': 'postalcode value' - } - } - ], - 'filter': { - 'term': { - 'layer': 'address' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.address', + 'boost': 10, + 'must': [ + { + 'match_phrase': { + 'address_parts.number': 'number value' + } + }, + { + 'match_phrase': { + 'address_parts.street': 'street value' + } + }, + { + 'multi_match': { + 'query': 'neighbourhood value', + 'type': 'phrase', + 'fields': [ + 'parent.neighbourhood', + 'parent.neighbourhood_a' + ] + } + }, + { + 'multi_match': { + 'query': 'borough value', + 'type': 'phrase', + 'fields': [ + 'parent.borough', + 'parent.borough_a' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] } } - }, - { - 'bool': { - '_name': 'fallback.postalcode', - 'must': [ - { - 'multi_match': { - 'query': 'postalcode value', - 'type': 'phrase', - 'fields': [ - 'parent.postalcode' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'postalcode' - } + ], + 'should': [ + { + 'match_phrase': { + 'address_parts.zip': 'postalcode value' } } - }, - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - }, - { - 'multi_match': { - 'query': 'neighbourhood value', - 'type': 'phrase', - 'fields': [ - 'parent.neighbourhood', - 'parent.neighbourhood_a' - ] - } - }, - { - 'multi_match': { - 'query': 'borough value', - 'type': 'phrase', - 'fields': [ - 'parent.borough', - 'parent.borough_a' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'should': [ - { - 'match_phrase': { - 'address_parts.zip': 'postalcode value' - } - } - ], - 'filter': { - 'term': { - 'layer': 'street' - } + ], + 'filter': { + 'term': { + 'layer': 'address' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.postalcode', + 'must': [ + { + 'multi_match': { + 'query': 'postalcode value', + 'type': 'phrase', + 'fields': [ + 'parent.postalcode' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'postalcode' } - }, - { - 'bool': { - '_name': 'fallback.neighbourhood', - 'must': [ - { - 'multi_match': { - 'query': 'neighbourhood value', - 'type': 'phrase', - 'fields': [ - 'parent.neighbourhood', - 'parent.neighbourhood_a' - ] - } - }, - { - 'multi_match': { - 'query': 'borough value', - 'type': 'phrase', - 'fields': [ - 'parent.borough', - 'parent.borough_a' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'neighbourhood' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' + } + }, + { + 'multi_match': { + 'query': 'neighbourhood value', + 'type': 'phrase', + 'fields': [ + 'parent.neighbourhood', + 'parent.neighbourhood_a' + ] + } + }, + { + 'multi_match': { + 'query': 'borough value', + 'type': 'phrase', + 'fields': [ + 'parent.borough', + 'parent.borough_a' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] } } - }, - { - 'bool': { - '_name': 'fallback.borough', - 'must': [ - { - 'multi_match': { - 'query': 'borough value', - 'type': 'phrase', - 'fields': [ - 'parent.borough', - 'parent.borough_a' - ] - } - }, - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a', - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'borough' - } + ], + 'should': [ + { + 'match_phrase': { + 'address_parts.zip': 'postalcode value' } } - }, - { - 'bool': { - '_name': 'fallback.locality', - 'must': [ - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.locality', - 'parent.locality_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'locality' - } + ], + 'filter': { + 'term': { + 'layer': 'street' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.neighbourhood', + 'must': [ + { + 'multi_match': { + 'query': 'neighbourhood value', + 'type': 'phrase', + 'fields': [ + 'parent.neighbourhood', + 'parent.neighbourhood_a' + ] + } + }, + { + 'multi_match': { + 'query': 'borough value', + 'type': 'phrase', + 'fields': [ + 'parent.borough', + 'parent.borough_a' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'neighbourhood' } - }, - { - 'bool': { - '_name': 'fallback.localadmin', - 'must': [ - { - 'multi_match': { - 'query': 'city value', - 'type': 'phrase', - 'fields': [ - 'parent.localadmin', - 'parent.localadmin_a' - ] - } - }, - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a', - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'localadmin' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.borough', + 'must': [ + { + 'multi_match': { + 'query': 'borough value', + 'type': 'phrase', + 'fields': [ + 'parent.borough', + 'parent.borough_a' + ] + } + }, + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a', + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'borough' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.locality', + 'must': [ + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.locality', + 'parent.locality_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] } } - }, - { - 'bool': { - '_name': 'fallback.county', - 'must': [ - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.county', - 'parent.county_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'county' - } + ], + 'filter': { + 'term': { + 'layer': 'locality' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.localadmin', + 'must': [ + { + 'multi_match': { + 'query': 'city value', + 'type': 'phrase', + 'fields': [ + 'parent.localadmin', + 'parent.localadmin_a' + ] + } + }, + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a', + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'localadmin' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.county', + 'must': [ + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.county', + 'parent.county_a' + ] } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'county' } - }, - { - 'bool': { - '_name': 'fallback.macrocounty', - 'must': [ - { - 'multi_match': { - 'query': 'county value', - 'type': 'phrase', - 'fields': [ - 'parent.macrocounty', - 'parent.macrocounty_a' - ] - } - }, - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a', - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'macrocounty' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.macrocounty', + 'must': [ + { + 'multi_match': { + 'query': 'county value', + 'type': 'phrase', + 'fields': [ + 'parent.macrocounty', + 'parent.macrocounty_a' + ] + } + }, + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a', + 'parent.macroregion', + 'parent.macroregion_a' + ] } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'macrocounty' } - }, - { - 'bool': { - '_name': 'fallback.region', - 'must': [ - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.region', - 'parent.region_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'region' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.region', + 'must': [ + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.region', + 'parent.region_a' + ] } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'region' } - }, - { - 'bool': { - '_name': 'fallback.macroregion', - 'must': [ - { - 'multi_match': { - 'query': 'state value', - 'type': 'phrase', - 'fields': [ - 'parent.macroregion', - 'parent.macroregion_a' - ] - } - }, - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a', - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'macroregion' - } + } + } + }, + { + 'bool': { + '_name': 'fallback.macroregion', + 'must': [ + { + 'multi_match': { + 'query': 'state value', + 'type': 'phrase', + 'fields': [ + 'parent.macroregion', + 'parent.macroregion_a' + ] + } + }, + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a', + 'parent.dependency', + 'parent.dependency_a' + ] } } - }, - { - 'bool': { - '_name': 'fallback.dependency', - 'must': [ - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.dependency', - 'parent.dependency_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'dependency' - } + ], + 'filter': { + 'term': { + 'layer': 'macroregion' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.dependency', + 'must': [ + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.dependency', + 'parent.dependency_a' + ] } } - }, - { - 'bool': { - '_name': 'fallback.country', - 'must': [ - { - 'multi_match': { - 'query': 'country value', - 'type': 'phrase', - 'fields': [ - 'parent.country', - 'parent.country_a' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'country' - } + ], + 'filter': { + 'term': { + 'layer': 'dependency' + } + } + } + }, + { + 'bool': { + '_name': 'fallback.country', + 'must': [ + { + 'multi_match': { + 'query': 'country value', + 'type': 'phrase', + 'fields': [ + 'parent.country', + 'parent.country_a' + ] } } + ], + 'filter': { + 'term': { + 'layer': 'country' + } } - ] - } - }, - 'filter': { - 'bool': { - 'must': [] + } } - } + ] } }, 'max_boost': 20, diff --git a/test/unit/fixture/search_fallback_postalcode_only.js b/test/unit/fixture/search_fallback_postalcode_only.js index 4519e166..76b2dbbf 100644 --- a/test/unit/fixture/search_fallback_postalcode_only.js +++ b/test/unit/fixture/search_fallback_postalcode_only.js @@ -2,39 +2,31 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.postalcode', - 'must': [ - { - 'multi_match': { - 'query': '90210', - 'type': 'phrase', - 'fields': [ - 'parent.postalcode' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'postalcode' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.postalcode', + 'must': [ + { + 'multi_match': { + 'query': '90210', + 'type': 'phrase', + 'fields': [ + 'parent.postalcode' + ] } } + ], + 'filter': { + 'term': { + 'layer': 'postalcode' + } } - ] - } - }, - 'filter': { - 'bool': { - 'must': [] + } } - } + ] } }, 'max_boost': 20, diff --git a/test/unit/fixture/search_linguistic_bbox.js b/test/unit/fixture/search_linguistic_bbox.js index e74f6c79..1692b8b9 100644 --- a/test/unit/fixture/search_linguistic_bbox.js +++ b/test/unit/fixture/search_linguistic_bbox.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_focus.js b/test/unit/fixture/search_linguistic_focus.js index a63400b3..ac48702e 100644 --- a/test/unit/fixture/search_linguistic_focus.js +++ b/test/unit/fixture/search_linguistic_focus.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_focus_bbox.js b/test/unit/fixture/search_linguistic_focus_bbox.js index 7f6c8528..0aed4961 100644 --- a/test/unit/fixture/search_linguistic_focus_bbox.js +++ b/test/unit/fixture/search_linguistic_focus_bbox.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_focus_null_island.js b/test/unit/fixture/search_linguistic_focus_null_island.js index da12154a..6ba7aa7d 100644 --- a/test/unit/fixture/search_linguistic_focus_null_island.js +++ b/test/unit/fixture/search_linguistic_focus_null_island.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_only.js b/test/unit/fixture/search_linguistic_only.js index 0117e03b..e30751ea 100644 --- a/test/unit/fixture/search_linguistic_only.js +++ b/test/unit/fixture/search_linguistic_only.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_viewport.js b/test/unit/fixture/search_linguistic_viewport.js index 0117e03b..e30751ea 100644 --- a/test/unit/fixture/search_linguistic_viewport.js +++ b/test/unit/fixture/search_linguistic_viewport.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_linguistic_viewport_min_diagonal.js b/test/unit/fixture/search_linguistic_viewport_min_diagonal.js index 0117e03b..e30751ea 100644 --- a/test/unit/fixture/search_linguistic_viewport_min_diagonal.js +++ b/test/unit/fixture/search_linguistic_viewport_min_diagonal.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_with_category_filtering.js b/test/unit/fixture/search_with_category_filtering.js index 05f9ec4e..73935587 100644 --- a/test/unit/fixture/search_with_category_filtering.js +++ b/test/unit/fixture/search_with_category_filtering.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/search_with_source_filtering.js b/test/unit/fixture/search_with_source_filtering.js index 0e9010c2..6797aecf 100644 --- a/test/unit/fixture/search_with_source_filtering.js +++ b/test/unit/fixture/search_with_source_filtering.js @@ -2,32 +2,29 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.street', - 'boost': 5, - 'must': [ - { - 'match_phrase': { - 'address_parts.street': 'street value' - } - } - ], - 'should': [], - 'filter': { - 'term': { - 'layer': 'street' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.street', + 'boost': 5, + 'must': [ + { + 'match_phrase': { + 'address_parts.street': 'street value' } } + ], + 'should': [], + 'filter': { + 'term': { + 'layer': 'street' + } } - ] + } } - }, + ], 'filter': { 'bool': { 'must': [ diff --git a/test/unit/fixture/structured_geocoding/boundary_country.json b/test/unit/fixture/structured_geocoding/boundary_country.json index 182da5a9..edff5d63 100644 --- a/test/unit/fixture/structured_geocoding/boundary_country.json +++ b/test/unit/fixture/structured_geocoding/boundary_country.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -59,4 +56,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/fallback.json b/test/unit/fixture/structured_geocoding/fallback.json index 58d0ce8c..7b737ffd 100644 --- a/test/unit/fixture/structured_geocoding/fallback.json +++ b/test/unit/fixture/structured_geocoding/fallback.json @@ -2,838 +2,830 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [ - { - "bool": { - "_name": "fallback.venue", - "must": [ - { - "multi_match": { - "query": "query value", - "type": "phrase", - "fields": [ - "phrase.default", - "category" - ] - } - }, - { - "multi_match": { - "query": "neighbourhood value", - "type": "phrase", - "fields": [ - "parent.neighbourhood", - "parent.neighbourhood_a" - ] - } - }, - { - "multi_match": { - "query": "borough value", - "type": "phrase", - "fields": [ - "parent.borough", - "parent.borough_a" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "venue" - } + "bool": { + "minimum_should_match": 1, + "should": [ + { + "bool": { + "_name": "fallback.venue", + "must": [ + { + "multi_match": { + "query": "query value", + "type": "phrase", + "fields": [ + "phrase.default", + "category" + ] + } + }, + { + "multi_match": { + "query": "neighbourhood value", + "type": "phrase", + "fields": [ + "parent.neighbourhood", + "parent.neighbourhood_a" + ] + } + }, + { + "multi_match": { + "query": "borough value", + "type": "phrase", + "fields": [ + "parent.borough", + "parent.borough_a" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.address", - "must": [ - { - "match_phrase": { - "address_parts.number": "number value" - } - }, - { - "match_phrase": { - "address_parts.street": "street value" - } - }, - { - "multi_match": { - "query": "neighbourhood value", - "type": "phrase", - "fields": [ - "parent.neighbourhood", - "parent.neighbourhood_a" - ] - } - }, - { - "multi_match": { - "query": "borough value", - "type": "phrase", - "fields": [ - "parent.borough", - "parent.borough_a" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "should": [ - { - "match_phrase": { - "address_parts.zip": "postalcode value" - } - } - ], - "filter": { - "term": { - "layer": "address" - } - }, - "boost": 10 + ], + "filter": { + "term": { + "layer": "venue" } - }, - { - "bool": { - "_name": "fallback.street", - "must": [ - { - "match_phrase": { - "address_parts.street": "street value" - } - }, - { - "multi_match": { - "query": "neighbourhood value", - "type": "phrase", - "fields": [ - "parent.neighbourhood", - "parent.neighbourhood_a" - ] - } - }, - { - "multi_match": { - "query": "borough value", - "type": "phrase", - "fields": [ - "parent.borough", - "parent.borough_a" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "should": [ - { - "match_phrase": { - "address_parts.zip": "postalcode value" - } - } - ], - "filter": { - "term": { - "layer": "street" - } - }, - "boost": 5 + } + } + }, + { + "bool": { + "_name": "fallback.address", + "must": [ + { + "match_phrase": { + "address_parts.number": "number value" + } + }, + { + "match_phrase": { + "address_parts.street": "street value" + } + }, + { + "multi_match": { + "query": "neighbourhood value", + "type": "phrase", + "fields": [ + "parent.neighbourhood", + "parent.neighbourhood_a" + ] + } + }, + { + "multi_match": { + "query": "borough value", + "type": "phrase", + "fields": [ + "parent.borough", + "parent.borough_a" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] + } } - }, - { - "bool": { - "_name": "fallback.postalcode", - "must": [ - { - "multi_match": { - "query": "postalcode value", - "type": "phrase", - "fields": [ - "parent.postalcode" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "postalcode" - } + ], + "should": [ + { + "match_phrase": { + "address_parts.zip": "postalcode value" } } + ], + "filter": { + "term": { + "layer": "address" + } }, - { - "bool": { - "_name": "fallback.neighbourhood", - "must": [ - { - "multi_match": { - "query": "neighbourhood value", - "type": "phrase", - "fields": [ - "parent.neighbourhood", - "parent.neighbourhood_a" - ] - } - }, - { - "multi_match": { - "query": "borough value", - "type": "phrase", - "fields": [ - "parent.borough", - "parent.borough_a" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "neighbourhood" - } + "boost": 10 + } + }, + { + "bool": { + "_name": "fallback.street", + "must": [ + { + "match_phrase": { + "address_parts.street": "street value" + } + }, + { + "multi_match": { + "query": "neighbourhood value", + "type": "phrase", + "fields": [ + "parent.neighbourhood", + "parent.neighbourhood_a" + ] + } + }, + { + "multi_match": { + "query": "borough value", + "type": "phrase", + "fields": [ + "parent.borough", + "parent.borough_a" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.borough", - "must": [ - { - "multi_match": { - "query": "borough value", - "type": "phrase", - "fields": [ - "parent.borough", - "parent.borough_a" - ] - } - }, - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a", - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "borough" - } + ], + "should": [ + { + "match_phrase": { + "address_parts.zip": "postalcode value" } } + ], + "filter": { + "term": { + "layer": "street" + } }, - { - "bool": { - "_name": "fallback.locality", - "must": [ - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.locality", - "parent.locality_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "locality" - } + "boost": 5 + } + }, + { + "bool": { + "_name": "fallback.postalcode", + "must": [ + { + "multi_match": { + "query": "postalcode value", + "type": "phrase", + "fields": [ + "parent.postalcode" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.localadmin", - "must": [ - { - "multi_match": { - "query": "city value", - "type": "phrase", - "fields": [ - "parent.localadmin", - "parent.localadmin_a" - ] - } - }, - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a", - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "localadmin" - } + ], + "filter": { + "term": { + "layer": "postalcode" + } + } + } + }, + { + "bool": { + "_name": "fallback.neighbourhood", + "must": [ + { + "multi_match": { + "query": "neighbourhood value", + "type": "phrase", + "fields": [ + "parent.neighbourhood", + "parent.neighbourhood_a" + ] + } + }, + { + "multi_match": { + "query": "borough value", + "type": "phrase", + "fields": [ + "parent.borough", + "parent.borough_a" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.county", - "must": [ - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.county", - "parent.county_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "county" - } + ], + "filter": { + "term": { + "layer": "neighbourhood" + } + } + } + }, + { + "bool": { + "_name": "fallback.borough", + "must": [ + { + "multi_match": { + "query": "borough value", + "type": "phrase", + "fields": [ + "parent.borough", + "parent.borough_a" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.macrocounty", - "must": [ - { - "multi_match": { - "query": "county value", - "type": "phrase", - "fields": [ - "parent.macrocounty", - "parent.macrocounty_a" - ] - } - }, - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a", - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "macrocounty" - } + ], + "filter": { + "term": { + "layer": "borough" + } + } + } + }, + { + "bool": { + "_name": "fallback.locality", + "must": [ + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.region", - "must": [ - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.region", - "parent.region_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "region" - } + ], + "filter": { + "term": { + "layer": "locality" + } + } + } + }, + { + "bool": { + "_name": "fallback.localadmin", + "must": [ + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.macroregion", - "must": [ - { - "multi_match": { - "query": "state value", - "type": "phrase", - "fields": [ - "parent.macroregion", - "parent.macroregion_a" - ] - } - }, - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a", - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "macroregion" - } + ], + "filter": { + "term": { + "layer": "localadmin" + } + } + } + }, + { + "bool": { + "_name": "fallback.county", + "must": [ + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.dependency", - "must": [ - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.dependency", - "parent.dependency_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "dependency" - } + ], + "filter": { + "term": { + "layer": "county" + } + } + } + }, + { + "bool": { + "_name": "fallback.macrocounty", + "must": [ + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } - }, - { - "bool": { - "_name": "fallback.country", - "must": [ - { - "multi_match": { - "query": "country value", - "type": "phrase", - "fields": [ - "parent.country", - "parent.country_a" - ] - } - } - ], - "filter": { - "term": { - "layer": "country" - } + ], + "filter": { + "term": { + "layer": "macrocounty" + } + } + } + }, + { + "bool": { + "_name": "fallback.region", + "must": [ + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] } } + ], + "filter": { + "term": { + "layer": "region" + } } - ] - } - }, - "filter": { - "bool": { - "must": [] + } + }, + { + "bool": { + "_name": "fallback.macroregion", + "must": [ + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] + } + } + ], + "filter": { + "term": { + "layer": "macroregion" + } + } + } + }, + { + "bool": { + "_name": "fallback.dependency", + "must": [ + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.dependency", + "parent.dependency_a" + ] + } + } + ], + "filter": { + "term": { + "layer": "dependency" + } + } + } + }, + { + "bool": { + "_name": "fallback.country", + "must": [ + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a" + ] + } + } + ], + "filter": { + "term": { + "layer": "country" + } + } + } } - } + ] } }, "max_boost": 20, diff --git a/test/unit/fixture/structured_geocoding/linguistic_bbox.json b/test/unit/fixture/structured_geocoding/linguistic_bbox.json index 2912a10d..94acc81d 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_bbox.json +++ b/test/unit/fixture/structured_geocoding/linguistic_bbox.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -62,4 +59,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus.json b/test/unit/fixture/structured_geocoding/linguistic_focus.json index cee04e8e..0bb126d1 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_focus.json +++ b/test/unit/fixture/structured_geocoding/linguistic_focus.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -65,4 +62,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json b/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json index 8c9e8cef..5b98f11f 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json +++ b/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json b/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json index 59fd11bb..d8723845 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json +++ b/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -65,4 +62,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/linguistic_only.json b/test/unit/fixture/structured_geocoding/linguistic_only.json index 17a54486..4de54360 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_only.json +++ b/test/unit/fixture/structured_geocoding/linguistic_only.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -51,4 +48,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/linguistic_viewport.json b/test/unit/fixture/structured_geocoding/linguistic_viewport.json index 17a54486..4de54360 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_viewport.json +++ b/test/unit/fixture/structured_geocoding/linguistic_viewport.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -51,4 +48,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json b/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json index 17a54486..4de54360 100644 --- a/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json +++ b/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json @@ -2,12 +2,9 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [], "filter": { "bool": { "must": [ @@ -51,4 +48,4 @@ ], "size": 10, "track_scores": true -} \ No newline at end of file +} diff --git a/test/unit/fixture/structured_geocoding/postalcode_only.js b/test/unit/fixture/structured_geocoding/postalcode_only.js index 7dafbaa0..2eb10d30 100644 --- a/test/unit/fixture/structured_geocoding/postalcode_only.js +++ b/test/unit/fixture/structured_geocoding/postalcode_only.js @@ -2,39 +2,31 @@ module.exports = { 'query': { 'function_score': { 'query': { - 'filtered': { - 'query': { - 'bool': { - 'should': [ - { - 'bool': { - '_name': 'fallback.postalcode', - 'must': [ - { - 'multi_match': { - 'query': 'postalcode value', - 'type': 'phrase', - 'fields': [ - 'parent.postalcode' - ] - } - } - ], - 'filter': { - 'term': { - 'layer': 'postalcode' - } + 'bool': { + 'minimum_should_match': 1, + 'should': [ + { + 'bool': { + '_name': 'fallback.postalcode', + 'must': [ + { + 'multi_match': { + 'query': 'postalcode value', + 'type': 'phrase', + 'fields': [ + 'parent.postalcode' + ] } } + ], + 'filter': { + 'term': { + 'layer': 'postalcode' + } } - ] - } - }, - 'filter': { - 'bool': { - 'must': [] + } } - } + ] } }, 'max_boost': 20, diff --git a/test/unit/fixture/structured_geocoding/with_source_filtering.json b/test/unit/fixture/structured_geocoding/with_source_filtering.json index 659d5eb4..77e4fb87 100644 --- a/test/unit/fixture/structured_geocoding/with_source_filtering.json +++ b/test/unit/fixture/structured_geocoding/with_source_filtering.json @@ -2,12 +2,10 @@ "query": { "function_score": { "query": { - "filtered": { - "query": { - "bool": { - "should": [] - } - }, + "bool": { + "minimum_should_match": 1, + "should": [ + ], "filter": { "bool": { "must": [ @@ -51,4 +49,4 @@ ], "size": 20, "track_scores": true -} \ No newline at end of file +} From 3097bcfa2ad20df5e3f2fd9bd56db6c41e78d573 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 7 Jul 2017 21:22:27 +0000 Subject: [PATCH 06/20] fix(package): update pelias-model to version 4.10.1 Closes #924 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a5cbe2e..ad9d83a5 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.1.2", - "pelias-model": "4.9.0", + "pelias-model": "4.10.1", "pelias-query": "8.16.1", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.8.3", From 9479eccea410ae48dec103c11b8d11c87983cb5c Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 8 Jul 2017 04:35:32 +0000 Subject: [PATCH 07/20] fix(package): update pelias-model to version 4.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad9d83a5..3a8699f5 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.1.2", - "pelias-model": "4.10.1", + "pelias-model": "4.11.0", "pelias-query": "8.16.1", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.8.3", From a16cc68f3213d0a655bc83ecece9eb9ed1b2ca24 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 10 Jul 2017 14:52:58 +0000 Subject: [PATCH 08/20] fix(package): update pelias-model to version 5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a8699f5..9e06b581 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.1.2", - "pelias-model": "4.11.0", + "pelias-model": "5.0.0", "pelias-query": "8.16.1", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.8.3", From f67664c3e04a1168a37376060494e45bce21502d Mon Sep 17 00:00:00 2001 From: Lily He Date: Wed, 5 Jul 2017 17:18:46 -0400 Subject: [PATCH 09/20] location bias feature - sets default focus.point --- sanitizer/_location_bias.js | 18 ++++++ schema.js | 6 +- test/unit/run.js | 1 + test/unit/sanitizer/_location_bias.js | 90 +++++++++++++++++++++++++++ test/unit/schema.js | 78 +++++++++++++++++++++++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 sanitizer/_location_bias.js create mode 100644 test/unit/sanitizer/_location_bias.js diff --git a/sanitizer/_location_bias.js b/sanitizer/_location_bias.js new file mode 100644 index 00000000..ee6646f6 --- /dev/null +++ b/sanitizer/_location_bias.js @@ -0,0 +1,18 @@ +/* +Set a focus.lat and focus.lon if specified in pelias config +*/ +var _ = require('lodash'); + +function setup(defaultParameters){ + return function setLocationBias(req, res, next){ + if (_.isUndefined(req.clean) || _.isUndefined(defaultParameters['focus.point.lat']) || _.isUndefined(defaultParameters['focus.point.lon'])) { + return next(); + } + req.clean['focus.point.lat'] = defaultParameters['focus.point.lat']; + req.clean['focus.point.lon'] = defaultParameters['focus.point.lon']; + next(); + }; +} + + +module.exports = setup; diff --git a/schema.js b/schema.js index df544677..e261cfe6 100644 --- a/schema.js +++ b/schema.js @@ -39,7 +39,11 @@ module.exports = Joi.object().keys({ timeout: Joi.number().integer().optional().default(250).min(0), retries: Joi.number().integer().optional().default(3).min(0), }).unknown(false).requiredKeys('url') - }).unknown(false).default({}) // default api.services to an empty object + }).unknown(false).default({}), // default api.services to an empty object + defaultParameters: Joi.object().keys({ + 'focus.point.lat': Joi.number().optional().min(-90).max(90), + 'focus.point.lon': Joi.number().optional().min(-180).max(180), + }).unknown(true).default({}) }).requiredKeys('version', 'indexName', 'host').unknown(true), esclient: Joi.object().keys({ diff --git a/test/unit/run.js b/test/unit/run.js index 92d258fa..b60f06c5 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -64,6 +64,7 @@ var tests = [ require('./sanitizer/_ids'), require('./sanitizer/_iso2_to_iso3'), require('./sanitizer/_layers'), + require('./sanitizer/_location_bias'), require('./sanitizer/_city_name_standardizer'), require('./sanitizer/_single_scalar_parameters'), require('./sanitizer/_size'), diff --git a/test/unit/sanitizer/_location_bias.js b/test/unit/sanitizer/_location_bias.js new file mode 100644 index 00000000..c0f48cf9 --- /dev/null +++ b/test/unit/sanitizer/_location_bias.js @@ -0,0 +1,90 @@ +var setup = require('../../../sanitizer/_location_bias'); + +module.exports.tests = {}; + +module.exports.tests.setLocationBias = function(test, common) { + test('set focus point', t => { + var defaultParameters = { // specify focus point latitude and longitude + 'focus.point.lat': 12.12121212, + 'focus.point.lon': 21.21212121 + }; + var locationBias = setup(defaultParameters); + var req = { + clean: {} + }; + var expected = { + clean: { + 'focus.point.lat': 12.12121212, + 'focus.point.lon': 21.21212121 + } + }; + + locationBias(req, undefined, () => { + t.deepEqual(req, expected, 'focus point should be set'); + t.end(); + }); + }); + + test('undefined req.clean', t => { + var defaultParameters = { + 'focus.point.lat': 12.12121212, + 'focus.point.lon': 21.21212121 + }; + var locationBias = setup(defaultParameters); + var req = {}; + var expected = {}; + + locationBias(req, undefined, () => { + t.deepEqual(req, expected, 'should be unmodified' ); + t.end(); + }); + }); + + test('focusPointLat is undefined', t => { + var defaultParameters = { + 'focus.point.lon': 12.2121212 + }; + var locationBias = setup(defaultParameters); + var req = { + clean: {} + }; + var expected = { + clean: {} + }; + + locationBias(req, undefined, () => { + t.deepEqual(req, expected, 'should be unmodified' ); + t.end(); + }); + }); + + test('focusPointLon is undefined', t => { + var defaultParameters = { + 'focus.point.lat': 12.2121212 + }; + var locationBias = setup(defaultParameters); + var req = { + clean: {} + }; + var expected = { + clean: {} + }; + + locationBias(req, undefined, () => { + t.deepEqual(req, expected, 'should be unmodified' ); + t.end(); + }); + }); + +}; + +module.exports.all = function (tape, common) { + + function test(name, testFunction) { + return tape('[middleware] locationBias: ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/schema.js b/test/unit/schema.js index d48c7392..332347dd 100644 --- a/test/unit/schema.js +++ b/test/unit/schema.js @@ -26,6 +26,10 @@ module.exports.tests.completely_valid = (test, common) => { placeholder: { url: 'http://locahost' } + }, + defaultParameters: { + 'focus.point.lat': 19, + 'focus.point.lon': 91 } }, esclient: { @@ -457,6 +461,80 @@ module.exports.tests.api_validation = (test, common) => { }); + test('non-number defaultParameters.focus.point.lat should throw error', (t) => { + [null, 'string', {}, [], false].forEach((value) => { + const config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + defaultParameters: { + 'focus.point.lat': value + } + }, + esclient: {} + }; + + const result = Joi.validate(config, schema); + + t.equals(result.error.details.length, 1); + t.equals(result.error.details[0].message, '"focus.point.lat" must be a number'); + + }); + + t.end(); + + }); + + test('non-number defaultParameters.focus.point.lon should throw error', (t) => { + [null, 'string', {}, [], false].forEach((value) => { + const config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + defaultParameters: { + 'focus.point.lon': value + } + }, + esclient: {} + }; + + const result = Joi.validate(config, schema); + + t.equals(result.error.details.length, 1); + t.equals(result.error.details[0].message, '"focus.point.lon" must be a number'); + + }); + + t.end(); + + }); + + test('non-object api.defaultParameters should throw error', (t) => { + [null, 17, false, [], 'string'].forEach((value) => { + var config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + defaultParameters: value + }, + esclient: {} + }; + + const result = Joi.validate(config, schema); + + t.equals(result.error.details.length, 1); + t.equals(result.error.details[0].message, '"defaultParameters" must be an object'); + + }); + + t.end(); + + }); + + }; module.exports.tests.api_services_validation = (test, common) => { From 2e2ae9b0052cfe62b9ed9f6e807b0e51a740798d Mon Sep 17 00:00:00 2001 From: Lily He Date: Wed, 5 Jul 2017 17:23:13 -0400 Subject: [PATCH 10/20] added location_bias sanitizer to autocomplete, search, and structured_geocoding --- sanitizer/_location_bias.js | 4 +++- sanitizer/autocomplete.js | 1 + sanitizer/search.js | 1 + sanitizer/structured_geocoding.js | 1 + test/unit/sanitizer/autocomplete.js | 2 +- test/unit/sanitizer/search.js | 6 ++++++ test/unit/sanitizer/structured_geocoding.js | 5 +++++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sanitizer/_location_bias.js b/sanitizer/_location_bias.js index ee6646f6..2ecc76b6 100644 --- a/sanitizer/_location_bias.js +++ b/sanitizer/_location_bias.js @@ -5,7 +5,9 @@ var _ = require('lodash'); function setup(defaultParameters){ return function setLocationBias(req, res, next){ - if (_.isUndefined(req.clean) || _.isUndefined(defaultParameters['focus.point.lat']) || _.isUndefined(defaultParameters['focus.point.lon'])) { + if (_.isUndefined(req.clean) || + _.isUndefined(defaultParameters['focus.point.lat']) || + _.isUndefined(defaultParameters['focus.point.lon'])) { return next(); } req.clean['focus.point.lat'] = defaultParameters['focus.point.lat']; diff --git a/sanitizer/autocomplete.js b/sanitizer/autocomplete.js index 86f85447..bf959c78 100644 --- a/sanitizer/autocomplete.js +++ b/sanitizer/autocomplete.js @@ -11,6 +11,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), // depends on the layers and sources sanitizers, must be run after them sources_and_layers: require('../sanitizer/_sources_and_layers'), private: require('../sanitizer/_flag_bool')('private', false), + location_bias: require('../sanitizer/_location_bias'), geo_autocomplete: require('../sanitizer/_geo_autocomplete'), boundary_country: require('../sanitizer/_boundary_country'), categories: require('../sanitizer/_categories') diff --git a/sanitizer/search.js b/sanitizer/search.js index 1d2507c2..d036eb2f 100644 --- a/sanitizer/search.js +++ b/sanitizer/search.js @@ -13,6 +13,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), // depends on the layers and sources sanitizers, must be run after them sources_and_layers: require('../sanitizer/_sources_and_layers'), private: require('../sanitizer/_flag_bool')('private', false), + location_bias: require('../sanitizer/_location_bias'), geo_search: require('../sanitizer/_geo_search'), boundary_country: require('../sanitizer/_boundary_country'), categories: require('../sanitizer/_categories'), diff --git a/sanitizer/structured_geocoding.js b/sanitizer/structured_geocoding.js index 29edce41..7f2248da 100644 --- a/sanitizer/structured_geocoding.js +++ b/sanitizer/structured_geocoding.js @@ -13,6 +13,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), // depends on the layers and sources sanitizers, must be run after them sources_and_layers: require('../sanitizer/_sources_and_layers'), private: require('../sanitizer/_flag_bool')('private', false), + location_bias: require('../sanitizer/_location_bias'), geo_search: require('../sanitizer/_geo_search'), boundary_country: require('../sanitizer/_boundary_country'), categories: require('../sanitizer/_categories') diff --git a/test/unit/sanitizer/autocomplete.js b/test/unit/sanitizer/autocomplete.js index 29db50ee..efdb54b9 100644 --- a/test/unit/sanitizer/autocomplete.js +++ b/test/unit/sanitizer/autocomplete.js @@ -6,7 +6,7 @@ module.exports.tests.sanitizers = function(test, common) { test('check sanitizer list', function (t) { var expected = [ 'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources', - 'sources_and_layers', 'private', 'geo_autocomplete', 'boundary_country', 'categories' + 'sources_and_layers', 'private', 'location_bias', 'geo_autocomplete', 'boundary_country', 'categories' ]; t.deepEqual(Object.keys(autocomplete.sanitizer_list), expected); t.end(); diff --git a/test/unit/sanitizer/search.js b/test/unit/sanitizer/search.js index e7a8e3fe..fca395c2 100644 --- a/test/unit/sanitizer/search.js +++ b/test/unit/sanitizer/search.js @@ -87,7 +87,12 @@ module.exports.tests.sanitize = (test, common) => { '../sanitizer/_geonames_warnings': () => { called_sanitizers.push('_geonames_warnings'); return { errors: [], warnings: [] }; + }, + '../sanitizer/_location_bias': () => { + called_sanitizers.push('_location_bias'); + return { errors: [], warnings: [] }; } + }); const expected_sanitizers = [ @@ -101,6 +106,7 @@ module.exports.tests.sanitize = (test, common) => { '_targets/sources', '_sources_and_layers', '_flag_bool', + '_location_bias', '_geo_search', '_boundary_country', '_categories', diff --git a/test/unit/sanitizer/structured_geocoding.js b/test/unit/sanitizer/structured_geocoding.js index 133be462..b93e1e71 100644 --- a/test/unit/sanitizer/structured_geocoding.js +++ b/test/unit/sanitizer/structured_geocoding.js @@ -83,6 +83,10 @@ module.exports.tests.sanitize = function(test, common) { called_sanitizers.push('_categories'); return { errors: [], warnings: [] }; }, + '../sanitizer/_location_bias': () => { + called_sanitizers.push('_location_bias'); + return { errors: [], warnings: [] }; + } }); var expected_sanitizers = [ @@ -96,6 +100,7 @@ module.exports.tests.sanitize = function(test, common) { '_targets/sources', '_sources_and_layers', '_flag_bool', + '_location_bias', '_geo_search', '_boundary_country', '_categories' From 40ca17b88678d5285d4d31318b535f95d40f738b Mon Sep 17 00:00:00 2001 From: Lily He Date: Fri, 7 Jul 2017 14:18:38 -0400 Subject: [PATCH 11/20] passed down peliasConfig.api schema to sanitizers --- routes/v1.js | 6 +- sanitizer/_location_bias.js | 23 ++-- sanitizer/autocomplete.js | 30 +++-- sanitizer/search.js | 54 ++++----- sanitizer/structured_geocoding.js | 51 +++++---- test/unit/sanitizer/_location_bias.js | 77 +++++-------- test/unit/sanitizer/autocomplete.js | 121 ++++++++++++++++++-- test/unit/sanitizer/search.js | 23 +++- test/unit/sanitizer/structured_geocoding.js | 23 +++- 9 files changed, 263 insertions(+), 145 deletions(-) diff --git a/routes/v1.js b/routes/v1.js index 1449887f..83d2fb78 100644 --- a/routes/v1.js +++ b/routes/v1.js @@ -129,7 +129,7 @@ function addRoutes(app, peliasConfig) { controllers.mdToHTML(peliasConfig.api, './public/attribution.md') ]), search: createRouter([ - sanitizers.search.middleware, + sanitizers.search.middleware(peliasConfig.api), middleware.requestLanguage, middleware.calcSize(), controllers.placeholder(placeholderService, placeholderShouldExecute), @@ -156,7 +156,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), structured: createRouter([ - sanitizers.structured_geocoding.middleware, + sanitizers.structured_geocoding.middleware(peliasConfig.api), middleware.requestLanguage, middleware.calcSize(), controllers.search(peliasConfig.api, esclient, queries.structured_geocoding, not(hasResponseDataOrRequestErrors)), @@ -177,7 +177,7 @@ function addRoutes(app, peliasConfig) { postProc.sendJSON ]), autocomplete: createRouter([ - sanitizers.autocomplete.middleware, + sanitizers.autocomplete.middleware(peliasConfig.api), middleware.requestLanguage, controllers.search(peliasConfig.api, esclient, queries.autocomplete, not(hasResponseDataOrRequestErrors)), postProc.distances('focus.point.'), diff --git a/sanitizer/_location_bias.js b/sanitizer/_location_bias.js index 2ecc76b6..329b34ed 100644 --- a/sanitizer/_location_bias.js +++ b/sanitizer/_location_bias.js @@ -1,18 +1,21 @@ -/* +const _ = require('lodash'); +/** Set a focus.lat and focus.lon if specified in pelias config +* @param {object} defaultParameters property of pelias config */ -var _ = require('lodash'); function setup(defaultParameters){ - return function setLocationBias(req, res, next){ - if (_.isUndefined(req.clean) || - _.isUndefined(defaultParameters['focus.point.lat']) || - _.isUndefined(defaultParameters['focus.point.lon'])) { - return next(); + + return function setLocationBias(raw, clean){ + if (!_.isUndefined(raw) && + !_.isUndefined(defaultParameters['focus.point.lat']) && + !_.isUndefined(defaultParameters['focus.point.lon'])) { + + raw['focus.point.lat'] = defaultParameters['focus.point.lat']; + raw['focus.point.lon'] = defaultParameters['focus.point.lon']; } - req.clean['focus.point.lat'] = defaultParameters['focus.point.lat']; - req.clean['focus.point.lon'] = defaultParameters['focus.point.lon']; - next(); + + return { errors: [], warnings: [] }; }; } diff --git a/sanitizer/autocomplete.js b/sanitizer/autocomplete.js index bf959c78..ed875bf5 100644 --- a/sanitizer/autocomplete.js +++ b/sanitizer/autocomplete.js @@ -1,7 +1,9 @@ var type_mapping = require('../helper/type_mapping'); +var sanitizeAll = require('../sanitizer/sanitizeAll'); -var sanitizeAll = require('../sanitizer/sanitizeAll'), - sanitizers = { +// middleware +module.exports.middleware = (_api_pelias_config) => { + var sanitizers = { singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), text: require('../sanitizer/_text_addressit'), tokenizer: require('../sanitizer/_tokenizer'), @@ -11,25 +13,21 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), // depends on the layers and sources sanitizers, must be run after them sources_and_layers: require('../sanitizer/_sources_and_layers'), private: require('../sanitizer/_flag_bool')('private', false), - location_bias: require('../sanitizer/_location_bias'), + location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), geo_autocomplete: require('../sanitizer/_geo_autocomplete'), boundary_country: require('../sanitizer/_boundary_country'), categories: require('../sanitizer/_categories') }; -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; - -// export sanitize for testing -module.exports.sanitize = sanitize; -module.exports.sanitizer_list = sanitizers; + var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; -// middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - if( err ){ - res.status(400); // 400 Bad Request - return next(err); - } + return function( req, res, next ){ + sanitize( req, function( err, clean ){ + if( err ){ + res.status(400); // 400 Bad Request + return next(err); + } next(); - }); + }); + }; }; diff --git a/sanitizer/search.js b/sanitizer/search.js index d036eb2f..99baa5a7 100644 --- a/sanitizer/search.js +++ b/sanitizer/search.js @@ -1,31 +1,33 @@ var type_mapping = require('../helper/type_mapping'); +var sanitizeAll = require('../sanitizer/sanitizeAll'); +// middleware +module.exports.middleware = (_api_pelias_config) => { + var sanitizers = { + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), + text: require('../sanitizer/_text'), + iso2_to_iso3: require('../sanitizer/_iso2_to_iso3'), + city_name_standardizer: require('../sanitizer/_city_name_standardizer'), + size: require('../sanitizer/_size')(/* use defaults*/), + layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), + sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), + // depends on the layers and sources sanitizers, must be run after them + sources_and_layers: require('../sanitizer/_sources_and_layers'), + private: require('../sanitizer/_flag_bool')('private', false), + location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), + geo_search: require('../sanitizer/_geo_search'), + boundary_country: require('../sanitizer/_boundary_country'), + categories: require('../sanitizer/_categories'), + // this can go away once geonames has been abrogated + geonames_warnings: require('../sanitizer/_geonames_warnings') + }; -var sanitizeAll = require('../sanitizer/sanitizeAll'), - sanitizers = { - singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), - quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), - text: require('../sanitizer/_text'), - iso2_to_iso3: require('../sanitizer/_iso2_to_iso3'), - city_name_standardizer: require('../sanitizer/_city_name_standardizer'), - size: require('../sanitizer/_size')(/* use defaults*/), - layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), - sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), - // depends on the layers and sources sanitizers, must be run after them - sources_and_layers: require('../sanitizer/_sources_and_layers'), - private: require('../sanitizer/_flag_bool')('private', false), - location_bias: require('../sanitizer/_location_bias'), - geo_search: require('../sanitizer/_geo_search'), - boundary_country: require('../sanitizer/_boundary_country'), - categories: require('../sanitizer/_categories'), - // this can go away once geonames has been abrogated - geonames_warnings: require('../sanitizer/_geonames_warnings') - }; + var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; + return function( req, res, next ){ + sanitize( req, function( err, clean ){ + next(); + }); + }; -// middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - next(); - }); }; diff --git a/sanitizer/structured_geocoding.js b/sanitizer/structured_geocoding.js index 7f2248da..e19a2837 100644 --- a/sanitizer/structured_geocoding.js +++ b/sanitizer/structured_geocoding.js @@ -1,29 +1,30 @@ var type_mapping = require('../helper/type_mapping'); - -var sanitizeAll = require('../sanitizer/sanitizeAll'), - sanitizers = { - singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), - quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), - synthesize_analysis: require('../sanitizer/_synthesize_analysis'), - iso2_to_iso3: require('../sanitizer/_iso2_to_iso3'), - city_name_standardizer: require('../sanitizer/_city_name_standardizer'), - size: require('../sanitizer/_size')(/* use defaults*/), - layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), - sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), - // depends on the layers and sources sanitizers, must be run after them - sources_and_layers: require('../sanitizer/_sources_and_layers'), - private: require('../sanitizer/_flag_bool')('private', false), - location_bias: require('../sanitizer/_location_bias'), - geo_search: require('../sanitizer/_geo_search'), - boundary_country: require('../sanitizer/_boundary_country'), - categories: require('../sanitizer/_categories') - }; - -var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; +var sanitizeAll = require('../sanitizer/sanitizeAll'); // middleware -module.exports.middleware = function( req, res, next ){ - sanitize( req, function( err, clean ){ - next(); - }); +module.exports.middleware = (_api_pelias_config) => { + var sanitizers = { + singleScalarParameters: require('../sanitizer/_single_scalar_parameters'), + quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'), + synthesize_analysis: require('../sanitizer/_synthesize_analysis'), + iso2_to_iso3: require('../sanitizer/_iso2_to_iso3'), + city_name_standardizer: require('../sanitizer/_city_name_standardizer'), + size: require('../sanitizer/_size')(/* use defaults*/), + layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), + sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), + // depends on the layers and sources sanitizers, must be run after them + sources_and_layers: require('../sanitizer/_sources_and_layers'), + private: require('../sanitizer/_flag_bool')('private', false), + location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), + geo_search: require('../sanitizer/_geo_search'), + boundary_country: require('../sanitizer/_boundary_country'), + categories: require('../sanitizer/_categories') + }; + var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; + + return function( req, res, next ){ + sanitize( req, function( err, clean ){ + next(); + }); + }; }; diff --git a/test/unit/sanitizer/_location_bias.js b/test/unit/sanitizer/_location_bias.js index c0f48cf9..b78cdac4 100644 --- a/test/unit/sanitizer/_location_bias.js +++ b/test/unit/sanitizer/_location_bias.js @@ -1,87 +1,70 @@ -var setup = require('../../../sanitizer/_location_bias'); +const setup = require('../../../sanitizer/_location_bias'); module.exports.tests = {}; module.exports.tests.setLocationBias = function(test, common) { test('set focus point', t => { - var defaultParameters = { // specify focus point latitude and longitude + const defaultParameters = { // specify focus point latitude and longitude 'focus.point.lat': 12.12121212, 'focus.point.lon': 21.21212121 }; - var locationBias = setup(defaultParameters); - var req = { - clean: {} - }; - var expected = { - clean: { + const locationBias = setup(defaultParameters); + const raw = {}; + const expected = { 'focus.point.lat': 12.12121212, 'focus.point.lon': 21.21212121 - } }; - locationBias(req, undefined, () => { - t.deepEqual(req, expected, 'focus point should be set'); - t.end(); - }); + locationBias(raw, undefined); + t.deepEqual(raw, expected, 'focus point should be set'); + t.end(); + }); - test('undefined req.clean', t => { - var defaultParameters = { + test('undefined raw', t => { + const defaultParameters = { 'focus.point.lat': 12.12121212, 'focus.point.lon': 21.21212121 }; - var locationBias = setup(defaultParameters); - var req = {}; - var expected = {}; + const locationBias = setup(defaultParameters); - locationBias(req, undefined, () => { - t.deepEqual(req, expected, 'should be unmodified' ); - t.end(); - }); + locationBias(undefined, undefined); + t.deepEqual(undefined, undefined, 'should be unmodified' ); + t.end(); }); test('focusPointLat is undefined', t => { - var defaultParameters = { + const defaultParameters = { 'focus.point.lon': 12.2121212 }; - var locationBias = setup(defaultParameters); - var req = { - clean: {} - }; - var expected = { - clean: {} - }; + const locationBias = setup(defaultParameters); + const raw = {}; + const expected = {}; - locationBias(req, undefined, () => { - t.deepEqual(req, expected, 'should be unmodified' ); - t.end(); - }); + locationBias(raw, undefined); + t.deepEqual(raw, expected, 'should be unmodified' ); + t.end(); }); test('focusPointLon is undefined', t => { - var defaultParameters = { + const defaultParameters = { 'focus.point.lat': 12.2121212 }; - var locationBias = setup(defaultParameters); - var req = { - clean: {} - }; - var expected = { - clean: {} - }; + const locationBias = setup(defaultParameters); + const raw = {}; + const expected = {}; - locationBias(req, undefined, () => { - t.deepEqual(req, expected, 'should be unmodified' ); + locationBias(raw, undefined); + t.deepEqual(raw, expected, 'should be unmodified' ); t.end(); - }); }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('[middleware] locationBias: ' + name, testFunction); + return tape(`SANITIZE _location_bias: ${name}`, testFunction); } for( var testCase in module.exports.tests ){ diff --git a/test/unit/sanitizer/autocomplete.js b/test/unit/sanitizer/autocomplete.js index efdb54b9..9f0b4a3a 100644 --- a/test/unit/sanitizer/autocomplete.js +++ b/test/unit/sanitizer/autocomplete.js @@ -1,21 +1,126 @@ -var autocomplete = require('../../../sanitizer/autocomplete'); +const proxyquire = require('proxyquire').noCallThru(); +const _ = require('lodash'); module.exports.tests = {}; module.exports.tests.sanitizers = function(test, common) { - test('check sanitizer list', function (t) { - var expected = [ - 'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources', - 'sources_and_layers', 'private', 'location_bias', 'geo_autocomplete', 'boundary_country', 'categories' + test('verify that all sanitizers were called as expected', function(t) { + var called_sanitizers = []; + + var autocomplete = proxyquire('../../../sanitizer/autocomplete', { + '../sanitizer/_single_scalar_parameters': () => { + called_sanitizers.push('_single_scalar_parameters'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_text_addressit': () => { + called_sanitizers.push('_text_addressit'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_tokenizer': () => { + called_sanitizers.push('_tokenizer'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_size': function() { + if (_.isEqual(_.values(arguments), [10, 10, 10])) { + return () => { + called_sanitizers.push('_size'); + return { errors: [], warnings: [] }; + }; + + } else { + throw new Error('incorrect parameters passed to _size'); + } + + }, + '../sanitizer/_targets': (type) => { + if (['layers', 'sources'].indexOf(type) !== -1) { + return () => { + called_sanitizers.push(`_targets/${type}`); + return { errors: [], warnings: [] }; + }; + + } + else { + throw new Error('incorrect parameters passed to _targets'); + } + + }, + '../sanitizer/_sources_and_layers': () => { + called_sanitizers.push('_sources_and_layers'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_flag_bool': function() { + if (arguments[0] === 'private' && arguments[1] === false) { + return () => { + called_sanitizers.push('_flag_bool'); + return { errors: [], warnings: [] }; + }; + + } + else { + throw new Error('incorrect parameters passed to _flag_bool'); + } + + }, + '../sanitizer/_location_bias': (defaultParameters) => { + if (defaultParameters.key === 'value'){ + return () => { + called_sanitizers.push('_location_bias'); + return { errors: [], warnings: [] }; + }; + } else { + throw new Error('incorrect parameter passed to _location_bias'); + } + }, + '../sanitizer/_geo_autocomplete': () => { + called_sanitizers.push('_geo_autocomplete'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_boundary_country': () => { + called_sanitizers.push('_boundary_country'); + return { errors: [], warnings: [] }; + }, + '../sanitizer/_categories': () => { + called_sanitizers.push('_categories'); + return { errors: [], warnings: [] }; + }, + }); + + const expected_sanitizers = [ + '_single_scalar_parameters', + '_text_addressit', + '_tokenizer', + '_size', + '_targets/layers', + '_targets/sources', + '_sources_and_layers', + '_flag_bool', + '_location_bias', + '_geo_autocomplete', + '_boundary_country', + '_categories' ]; - t.deepEqual(Object.keys(autocomplete.sanitizer_list), expected); - t.end(); + + const req = {}; + const res = {}; + + const middleware = autocomplete.middleware({ + defaultParameters: { + key: 'value' + } + }); + + middleware(req, res, () => { + t.deepEquals(called_sanitizers, expected_sanitizers); + t.end(); + }); + }); }; module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('SANTIZE /autocomplete ' + name, testFunction); + return tape('SANITIZE /autocomplete ' + name, testFunction); } for( var testCase in module.exports.tests ){ diff --git a/test/unit/sanitizer/search.js b/test/unit/sanitizer/search.js index fca395c2..214c9cbc 100644 --- a/test/unit/sanitizer/search.js +++ b/test/unit/sanitizer/search.js @@ -88,9 +88,15 @@ module.exports.tests.sanitize = (test, common) => { called_sanitizers.push('_geonames_warnings'); return { errors: [], warnings: [] }; }, - '../sanitizer/_location_bias': () => { - called_sanitizers.push('_location_bias'); - return { errors: [], warnings: [] }; + '../sanitizer/_location_bias': (defaultParameters) => { + if (defaultParameters.key === 'value'){ + return () => { + called_sanitizers.push('_location_bias'); + return { errors: [], warnings: [] }; + }; + } else { + throw new Error('incorrect parameter passed to _location_bias'); + } } }); @@ -116,17 +122,24 @@ module.exports.tests.sanitize = (test, common) => { const req = {}; const res = {}; - search.middleware(req, res, () => { + const middleware = search.middleware({ + defaultParameters: { + key: 'value' + } + }); + + middleware(req, res, () => { t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); + }); }; module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape(`SANTIZE /search ${name}`, testFunction); + return tape(`SANITIZE /search ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/unit/sanitizer/structured_geocoding.js b/test/unit/sanitizer/structured_geocoding.js index b93e1e71..3cc10432 100644 --- a/test/unit/sanitizer/structured_geocoding.js +++ b/test/unit/sanitizer/structured_geocoding.js @@ -83,9 +83,15 @@ module.exports.tests.sanitize = function(test, common) { called_sanitizers.push('_categories'); return { errors: [], warnings: [] }; }, - '../sanitizer/_location_bias': () => { - called_sanitizers.push('_location_bias'); - return { errors: [], warnings: [] }; + '../sanitizer/_location_bias': function (defaultParameters) { + if (defaultParameters.key === 'value'){ + return () => { + called_sanitizers.push('_location_bias'); + return { errors: [], warnings: [] }; + }; + } else { + throw new Error('incorrect parameter passed to _location_bias'); + } } }); @@ -109,17 +115,24 @@ module.exports.tests.sanitize = function(test, common) { var req = {}; var res = {}; - search.middleware(req, res, function(){ + const middleware = search.middleware({ + defaultParameters: { + key: 'value' + } + }); + + middleware(req, res, function(){ t.deepEquals(called_sanitizers, expected_sanitizers); t.end(); }); + }); }; module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('SANTIZE /structured ' + name, testFunction); + return tape('SANITIZE /structured ' + name, testFunction); } for( var testCase in module.exports.tests ){ From 5504240016479f404a70927ff9555f28ec10d924 Mon Sep 17 00:00:00 2001 From: Lily He Date: Mon, 10 Jul 2017 12:50:03 -0400 Subject: [PATCH 12/20] prevent overriding raw.focus.point.lat/lon --- sanitizer/_location_bias.js | 12 +++++++-- schema.js | 4 +-- test/unit/sanitizer/_location_bias.js | 36 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/sanitizer/_location_bias.js b/sanitizer/_location_bias.js index 329b34ed..4c9c7f8b 100644 --- a/sanitizer/_location_bias.js +++ b/sanitizer/_location_bias.js @@ -7,9 +7,17 @@ Set a focus.lat and focus.lon if specified in pelias config function setup(defaultParameters){ return function setLocationBias(raw, clean){ +/* +check that: +1. {object} raw exists +2. pelias-config included the properties focus.point.lat and focus.point.lon +3. raw.focus.point.lon and raw.focus.point.lat have not been set +*/ if (!_.isUndefined(raw) && !_.isUndefined(defaultParameters['focus.point.lat']) && - !_.isUndefined(defaultParameters['focus.point.lon'])) { + !_.isUndefined(defaultParameters['focus.point.lon']) && + !_.has(raw, 'focus.point.lon') && + !_.has(raw, 'focus.point.lat') ) { raw['focus.point.lat'] = defaultParameters['focus.point.lat']; raw['focus.point.lon'] = defaultParameters['focus.point.lon']; @@ -19,5 +27,5 @@ function setup(defaultParameters){ }; } - +// if focus.point.lat and focus.point.lon already exists, don't change module.exports = setup; diff --git a/schema.js b/schema.js index e261cfe6..e37cf055 100644 --- a/schema.js +++ b/schema.js @@ -41,8 +41,8 @@ module.exports = Joi.object().keys({ }).unknown(false).requiredKeys('url') }).unknown(false).default({}), // default api.services to an empty object defaultParameters: Joi.object().keys({ - 'focus.point.lat': Joi.number().optional().min(-90).max(90), - 'focus.point.lon': Joi.number().optional().min(-180).max(180), + 'focus.point.lat': Joi.number(), + 'focus.point.lon': Joi.number(), }).unknown(true).default({}) }).requiredKeys('version', 'indexName', 'host').unknown(true), diff --git a/test/unit/sanitizer/_location_bias.js b/test/unit/sanitizer/_location_bias.js index b78cdac4..6778f045 100644 --- a/test/unit/sanitizer/_location_bias.js +++ b/test/unit/sanitizer/_location_bias.js @@ -59,6 +59,42 @@ module.exports.tests.setLocationBias = function(test, common) { t.end(); }); + test('raw has focus.point.lon already', t => { + const defaultParameters = { + 'focus.point.lon': 12.2121212, + 'focus.point.lat': 12.2121212 + }; + const locationBias = setup(defaultParameters); + const raw = { + 'focus.point.lon': 43.4343434 + }; + const expected = { + 'focus.point.lon': 43.4343434 + }; + + locationBias(raw, undefined); + t.deepEqual(raw, expected, 'should be unmodified' ); + t.end(); + }); + + test('raw has focus.point.lat already', t => { + const defaultParameters = { + 'focus.point.lon': 12.2121212, + 'focus.point.lat': 12.2121212 + }; + const locationBias = setup(defaultParameters); + const raw = { + 'focus.point.lat': 34.3434343 + }; + const expected = { + 'focus.point.lat': 34.3434343 + }; + + locationBias(raw, undefined); + t.deepEqual(raw, expected, 'should be unmodified' ); + t.end(); + }); + }; module.exports.all = (tape, common) => { From f019f0ab5eeee01fc895f87aa3422b06ec861340 Mon Sep 17 00:00:00 2001 From: Lily He Date: Mon, 10 Jul 2017 14:17:45 -0400 Subject: [PATCH 13/20] deletd legacy routes and legacyURL code --- README.md | 2 -- app.js | 3 --- package.json | 1 - routes/legacy.js | 34 ---------------------------------- schema.js | 2 -- test/unit/schema.js | 24 ------------------------ 6 files changed, 66 deletions(-) delete mode 100644 routes/legacy.js diff --git a/README.md b/README.md index e066a575..3e3bfec3 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,6 @@ The API recognizes the following properties under the top-level `api` key in you |`host`|*yes*||specifies the url under which the http service is to run| |`textAnalyzer`|*no*|*addressit*|can be either `libpostal` or `addressit` however will soon be **deprecated** and only `libpostal` will be supported going forward| |`indexName`|*no*|*pelias*|name of the Elasticsearch index to be used when building queries| -|`legacyUrl`|*no*||the url to redirect to in case the user does not specify a version such as `v1` |`relativeScores`|*no*|true|if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable |`accessLog`|*no*||name of the format to use for access logs; may be any one of the [predefined values](https://github.com/expressjs/morgan#predefined-formats) in the `morgan` package. Defaults to `"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.| |`services`|*no*||service definitions for [point-in-polygon](https://github.com/pelias/pip-service) and [placholder](https://github.com/pelias/placeholder) services. If missing (which is not recommended), the point-in-polygon and placeholder services will not be called.| @@ -65,7 +64,6 @@ Example configuration file would look something like this: "api": { "host": "localhost:3100/v1/", "indexName": "foobar", - "legacyUrl": "pelias.mapzen.com", "relativeScores": true, "textAnalyzer": "libpostal", "services": { diff --git a/app.js b/app.js index 2034e96b..342f00eb 100644 --- a/app.js +++ b/app.js @@ -16,9 +16,6 @@ app.use( require('./middleware/jsonp') ); /** ----------------------- routes ----------------------- **/ -var legacy = require('./routes/legacy'); -legacy.addRoutes(app, peliasConfig.api); - var v1 = require('./routes/v1'); v1.addRoutes(app, peliasConfig); diff --git a/package.json b/package.json index 9e06b581..d61eacc9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "elasticsearch": "^12.0.1", "elasticsearch-exceptions": "0.0.4", "express": "^4.8.8", - "express-http-proxy": "^0.11.0", "extend": "^3.0.1", "geojson": "^0.4.0", "@mapbox/geojson-extent": "^0.3.1", diff --git a/routes/legacy.js b/routes/legacy.js deleted file mode 100644 index 1de4986d..00000000 --- a/routes/legacy.js +++ /dev/null @@ -1,34 +0,0 @@ -var proxy = require('express-http-proxy'); - -function addRoutes(app, peliasConfig) { - var sendToLegacy; - - if (!peliasConfig.hasOwnProperty('legacyUrl')) { - sendToLegacy = function redirectToV1(req, res, next) { - res.redirect(301, '/v1'); - }; - } - else { - sendToLegacy = proxy(peliasConfig.legacyUrl); - } - - // api root - app.get( '/', sendToLegacy ); - - // place API - app.get( '/place', sendToLegacy); - - // suggest APIs - app.get( '/suggest', sendToLegacy ); - app.get( '/suggest/nearby', sendToLegacy ); - app.get( '/suggest/coarse',sendToLegacy ); - - // search APIs - app.get( '/search', sendToLegacy); - app.get( '/search/coarse', sendToLegacy); - - // reverse API - app.get( '/reverse', sendToLegacy ); -} - -module.exports.addRoutes = addRoutes; diff --git a/schema.js b/schema.js index df544677..ca69ccfb 100644 --- a/schema.js +++ b/schema.js @@ -12,14 +12,12 @@ const Joi = require('joi'); // optional: // * api.accessLog (string) // * api.relativeScores (boolean) -// * api.legacyUrl (string) // * api.localization (flipNumberAndStreetCountries is array of 3 character strings) module.exports = Joi.object().keys({ api: Joi.object().keys({ version: Joi.string(), indexName: Joi.string(), host: Joi.string(), - legacyUrl: Joi.string(), accessLog: Joi.string(), relativeScores: Joi.boolean(), requestRetries: Joi.number().integer().min(0), diff --git a/test/unit/schema.js b/test/unit/schema.js index d48c7392..c3cf25de 100644 --- a/test/unit/schema.js +++ b/test/unit/schema.js @@ -12,7 +12,6 @@ module.exports.tests.completely_valid = (test, common) => { version: 'version value', indexName: 'index name value', host: 'host value', - legacyUrl: 'legacyUrl value', accessLog: 'accessLog value', relativeScores: true, localization: { @@ -160,29 +159,6 @@ module.exports.tests.api_validation = (test, common) => { }); - test('non-string api.legacyUrl should throw error', (t) => { - [null, 17, {}, [], true].forEach((value) => { - var config = { - api: { - version: 'version value', - indexName: 'index name value', - host: 'host value', - legacyUrl: value - }, - esclient: {} - }; - - const result = Joi.validate(config, schema); - - t.equals(result.error.details.length, 1); - t.equals(result.error.details[0].message, '"legacyUrl" must be a string'); - - }); - - t.end(); - - }); - test('non-string api.accessLog should throw error', (t) => { [null, 17, {}, [], true].forEach((value) => { var config = { From a66df9bbdc16581ef6b68dfa8df9b534612eabde Mon Sep 17 00:00:00 2001 From: Lily He Date: Mon, 10 Jul 2017 15:03:57 -0400 Subject: [PATCH 14/20] location bias description in README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e066a575..5c7680ab 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ The API recognizes the following properties under the top-level `api` key in you |`relativeScores`|*no*|true|if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable |`accessLog`|*no*||name of the format to use for access logs; may be any one of the [predefined values](https://github.com/expressjs/morgan#predefined-formats) in the `morgan` package. Defaults to `"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.| |`services`|*no*||service definitions for [point-in-polygon](https://github.com/pelias/pip-service) and [placholder](https://github.com/pelias/placeholder) services. If missing (which is not recommended), the point-in-polygon and placeholder services will not be called.| +|`defaultParameters.focus.point.lon`
`defaultParameters.focus.point.lat`|no | |default coordinates for focus point Example configuration file would look something like this: @@ -76,6 +77,10 @@ Example configuration file would look something like this: "url": "http://myplaceholderservice.com:5000" } } + "defaultParameters": { + "focus.point.lat": 12.121212, + "focus.point.lon": 21.212121 + } }, "interpolation": { "client": { From 57b133ba420aa256788e006c873ae9a5bcd308f4 Mon Sep 17 00:00:00 2001 From: Lily He Date: Thu, 13 Jul 2017 18:01:51 -0400 Subject: [PATCH 15/20] check and set default for undefined boundary circle radius in reverse --- query/reverse.js | 12 ++++++++++++ sanitizer/_geo_reverse.js | 5 ----- test/unit/query/reverse.js | 17 +++++++++++++++++ test/unit/sanitizer/_geo_reverse.js | 22 +--------------------- test/unit/sanitizer/nearby.js | 1 - test/unit/sanitizer/reverse.js | 1 - 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/query/reverse.js b/query/reverse.js index fbe1251d..dba05935 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -75,6 +75,18 @@ function generateQuery( clean ){ logStr += '[param:boundary_circle] '; } + // for coarse reverse when boundary circle radius is undefined + if( check.number(clean['boundary.circle.lat']) && + check.number(clean['boundary.circle.lon']) && + check.undefined(clean['boundary.circle.radius']) ){ + vs.set({ + 'boundary:circle:lat': clean['boundary.circle.lat'], + 'boundary:circle:lon': clean['boundary.circle.lon'], + 'boundary:circle:radius': defaults['boundary:circle:radius'] + }); + logStr += '[param:boundary_circle] '; + } + // boundary country if( check.string(clean['boundary.country']) ){ vs.set({ diff --git a/sanitizer/_geo_reverse.js b/sanitizer/_geo_reverse.js index 5a7195eb..1bb85043 100644 --- a/sanitizer/_geo_reverse.js +++ b/sanitizer/_geo_reverse.js @@ -29,11 +29,6 @@ module.exports = function sanitize( raw, clean ){ raw['boundary.circle.lat'] = clean['point.lat']; raw['boundary.circle.lon'] = clean['point.lon']; - // if no radius was passed, set the default - if ( _.isUndefined( raw['boundary.circle.radius'] ) ) { - raw['boundary.circle.radius'] = defaults['boundary:circle:radius']; - } - // santize the boundary.circle geo_common.sanitize_circle( 'boundary.circle', clean, raw, CIRCLE_IS_REQUIRED ); diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index d773224b..eab97188 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -61,6 +61,23 @@ module.exports.tests.query = function(test, common) { t.end(); }); + // for coarse reverse cases where boundary circle radius isn't used + test('undefined radius set to default radius', function(t) { + var query = generate({ + 'point.lat': 12.12121, + 'point.lon': 21.21212, + 'boundary.circle.lat': 12.12121, + 'boundary.circle.lon': 21.21212 + }); + + var compiled = JSON.parse( JSON.stringify( query ) ); + var expected = '1km'; + + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body.query.bool.filter[0].geo_distance.distance, expected, 'distance set to default boundary circle radius'); + t.end(); + }); + test('boundary.circle lat/lon/radius - overrides point.lat/lon when set', function(t) { var clean = { 'point.lat': 29.49136, diff --git a/test/unit/sanitizer/_geo_reverse.js b/test/unit/sanitizer/_geo_reverse.js index 4df32711..223cf9fa 100644 --- a/test/unit/sanitizer/_geo_reverse.js +++ b/test/unit/sanitizer/_geo_reverse.js @@ -84,31 +84,11 @@ module.exports.tests.success_conditions = (test, common) => { }); - test('boundary.circle.radius not specified should use default', (t) => { - const raw = { - 'point.lat': '12.121212', - 'point.lon': '21.212121' - }; - const clean = {}; - const errorsAndWarnings = sanitize(raw, clean); - - t.equals(raw['boundary.circle.lat'], 12.121212); - t.equals(raw['boundary.circle.lon'], 21.212121); - t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius'], 'should be from defaults'); - t.equals(clean['boundary.circle.lat'], 12.121212); - t.equals(clean['boundary.circle.lon'], 21.212121); - t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius']), 'should be same as raw'); - - t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }); - t.end(); - - }); - }; module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape(`SANTIZE _geo_reverse ${name}`, testFunction); + return tape(`SANITIZE _geo_reverse ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/unit/sanitizer/nearby.js b/test/unit/sanitizer/nearby.js index 1ba41f67..72be019a 100644 --- a/test/unit/sanitizer/nearby.js +++ b/test/unit/sanitizer/nearby.js @@ -8,7 +8,6 @@ var defaultClean = { 'point.lat': 0, 'point.lon': 0, 'boundary.circle.lat': 0, 'boundary.circle.lon': 0, - 'boundary.circle.radius': parseFloat(defaults['boundary:circle:radius']), size: 10, private: false }; diff --git a/test/unit/sanitizer/reverse.js b/test/unit/sanitizer/reverse.js index 430d3ffa..c7125743 100644 --- a/test/unit/sanitizer/reverse.js +++ b/test/unit/sanitizer/reverse.js @@ -10,7 +10,6 @@ var reverse = require('../../../sanitizer/reverse'), 'point.lon': 0, 'boundary.circle.lat': 0, 'boundary.circle.lon': 0, - 'boundary.circle.radius': parseFloat(defaults['boundary:circle:radius']), size: 10, private: false }; From 775fd1f5687e6ed644fc38deff961e3d71b16f25 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 18 Jul 2017 13:17:40 -0400 Subject: [PATCH 16/20] updated code+tests to findById name array output format --- middleware/changeLanguage.js | 8 +-- test/unit/middleware/changeLanguage.js | 84 +++++++++++++++++++++----- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/middleware/changeLanguage.js b/middleware/changeLanguage.js index d6449ae8..4822f55e 100644 --- a/middleware/changeLanguage.js +++ b/middleware/changeLanguage.js @@ -1,6 +1,7 @@ var logger = require( 'pelias-logger' ).get( 'api' ); var service = require('../service/language'); +const _ = require('lodash'); /** example response from language web service: @@ -28,7 +29,6 @@ example response from language web service: **/ function setup() { - var transport = service.findById(); var middleware = function(req, res, next) { @@ -145,18 +145,18 @@ function updateDocs( req, res, translations ){ if( !translations[id].hasOwnProperty( 'names' ) ){ continue; } // requested language is not available - if( !translations[id].names.hasOwnProperty( requestLanguage ) ){ + if (_.isEmpty(_.get(translations[id].names, requestLanguage, [] ))) { logger.info( '[language] [info]', 'missing translation', requestLanguage, id ); continue; } // translate 'parent.*' property - adminValues[i] = translations[id].names[ requestLanguage ]; + adminValues[i] = translations[id].names[ requestLanguage ][0]; // if the record is an admin record we also translate // the 'name.default' property. if( adminKey === doc.layer ){ - doc.name.default = translations[id].names[ requestLanguage ]; + doc.name.default = translations[id].names[ requestLanguage ][0]; } } } diff --git a/test/unit/middleware/changeLanguage.js b/test/unit/middleware/changeLanguage.js index 66b6d127..43daa3d9 100644 --- a/test/unit/middleware/changeLanguage.js +++ b/test/unit/middleware/changeLanguage.js @@ -2,6 +2,7 @@ var fs = require('fs'), tmp = require('tmp'), setup = require('../../../middleware/changeLanguage'); +const proxyquire = require('proxyquire').noCallThru(); // load middleware using the default pelias config var load = function(){ @@ -144,7 +145,7 @@ module.exports.tests.hit = function(test, common) { name: { default: 'London' }, parent: { locality_id: [ 101735809 ], - locaity: [ 'London' ] + locality: [ 'London' ] } } ]}; @@ -158,23 +159,23 @@ module.exports.tests.hit = function(test, common) { cb( null, { '101750367': { 'names': { - 'default':'London', - 'chi':'倫敦', - 'spa':'Londres', - 'eng':'London', - 'hin':'लंदन', - 'ara':'لندن', - 'por':'Londres', - 'ben':'লন্ডন', - 'rus':'Лондон', - 'jpn':'ロンドン', - 'kor':'런던' + 'default':['London'], + 'chi':['倫敦'], + 'spa':['Londres'], + 'eng':['London'], + 'hin':['लंदन'], + 'ara':['لندن'], + 'por':['Londres'], + 'ben':['লন্ডন'], + 'rus':['Лондон'], + 'jpn':['ロンドン'], + 'kor':['런던'] } }, '101735809': { 'names':{ - 'default':'London', - 'eng':'London' + 'default':['London'], + 'eng':['London'] } } }); @@ -195,13 +196,66 @@ module.exports.tests.hit = function(test, common) { name: { default: 'London' }, parent: { locality_id: [ 101735809 ], - locaity: [ 'London' ] + locality: [ 'London' ] } } ]}); t.end(); }); }); + + test('empty array name translation should not change the value', t => { + t.plan(2); + + const req = { language: { iso6393: 'ISO3 value' } }; + const res = { + data: [ + { + layer: 'locality', + name: { default: 'original name' }, + parent: { + locality_id: [ 123 ], + locality: [ 'original name' ] + } + } + ] + }; + + const changeLanguage = proxyquire('../../../middleware/changeLanguage', { + '../service/language': { + findById: () => ({ + query: (ids, callback) => { + t.deepEquals(ids, ['123']); + callback(null, { + '123': { + 'names': { + 'ISO3 value':[] + } + } + }); + } + }) + } + })(); + + changeLanguage(req, res, () => { + t.deepEqual( res, { data: [ + { + layer: 'locality', + name: { + default: 'original name' + }, + parent: { + locality_id: [ 123 ], + locality: [ 'original name' ] + } + } + ]}); + + }); + + }); + }; module.exports.all = function (tape, common) { From 2e90892b254e11fe8ba0ba2cba281c3382242e08 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 18 Jul 2017 13:36:27 -0400 Subject: [PATCH 17/20] info->debug to reduce log noise --- middleware/changeLanguage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/changeLanguage.js b/middleware/changeLanguage.js index 4822f55e..f242fa85 100644 --- a/middleware/changeLanguage.js +++ b/middleware/changeLanguage.js @@ -146,7 +146,7 @@ function updateDocs( req, res, translations ){ // requested language is not available if (_.isEmpty(_.get(translations[id].names, requestLanguage, [] ))) { - logger.info( '[language] [info]', 'missing translation', requestLanguage, id ); + logger.debug( '[language] [debug]', 'missing translation', requestLanguage, id ); continue; } From 67fc873bb7c927fd51cebe8953ec0a8a617836d8 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 19 Jul 2017 00:09:32 +0000 Subject: [PATCH 18/20] fix(package): update pelias-microservice-wrapper to version 1.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d61eacc9..d404ecb6 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "pelias-config": "2.11.0", "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", - "pelias-microservice-wrapper": "1.1.2", + "pelias-microservice-wrapper": "1.1.3", "pelias-model": "5.0.0", "pelias-query": "8.16.1", "pelias-sorting": "1.0.1", From 2a73bb34acb7ed22b214609cbc94a315a2a4aaba Mon Sep 17 00:00:00 2001 From: Lily He Date: Wed, 19 Jul 2017 10:38:07 -0400 Subject: [PATCH 19/20] combined checks for boundary circle radius into one block --- query/reverse.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/query/reverse.js b/query/reverse.js index dba05935..a9c1d25c 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -65,25 +65,24 @@ function generateQuery( clean ){ // 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']) && - check.number(clean['boundary.circle.radius']) ){ - vs.set({ - 'boundary:circle:lat': clean['boundary.circle.lat'], - 'boundary:circle:lon': clean['boundary.circle.lon'], - 'boundary:circle:radius': clean['boundary.circle.radius'] + 'km' - }); - logStr += '[param:boundary_circle] '; - } - - // for coarse reverse when boundary circle radius is undefined - if( check.number(clean['boundary.circle.lat']) && - check.number(clean['boundary.circle.lon']) && - check.undefined(clean['boundary.circle.radius']) ){ - vs.set({ - 'boundary:circle:lat': clean['boundary.circle.lat'], - 'boundary:circle:lon': clean['boundary.circle.lon'], - 'boundary:circle:radius': defaults['boundary:circle:radius'] - }); + check.number(clean['boundary.circle.lon']) ){ + + vs.set({ + 'boundary:circle:lat': clean['boundary.circle.lat'], + 'boundary:circle:lon': clean['boundary.circle.lon'] + }); + + if (check.undefined(clean['boundary.circle.radius'])){ + // for coarse reverse when boundary circle radius is undefined + vs.set({ + 'boundary:circle:radius': defaults['boundary:circle:radius'] + }); + } else if (check.number(clean['boundary.circle.radius'])){ + // plain reverse where boundary circle is a valid number + vs.set({ + 'boundary:circle:radius': clean['boundary.circle.radius'] + 'km' + }); + } logStr += '[param:boundary_circle] '; } From c458eabf9b2a38dc6c4f0c0606e69baf83264cfa Mon Sep 17 00:00:00 2001 From: Lily He Date: Thu, 20 Jul 2017 14:52:20 -0400 Subject: [PATCH 20/20] delete unused _details sanitizer --- sanitizer/_details.js | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 sanitizer/_details.js diff --git a/sanitizer/_details.js b/sanitizer/_details.js deleted file mode 100644 index c67f7c47..00000000 --- a/sanitizer/_details.js +++ /dev/null @@ -1,32 +0,0 @@ - -var _ = require('lodash'), - check = require('check-types'); - -var DEFAULT_DETAILS_BOOL = true; - -// validate inputs, convert types and apply defaults -function sanitize( raw, clean ){ - - // error & warning messages - var messages = { errors: [], warnings: [] }; - - if( !check.undefined( raw.details ) ){ - clean.details = isTruthy( raw.details ); - } else { - clean.details = DEFAULT_DETAILS_BOOL; - } - - return messages; -} - -// be lenient with 'truthy' values -function isTruthy(val) { - if( check.string( val ) ){ - return _.includes( ['true', '1'], val ); - } - - return val === 1 || val === true; -} - -// export function -module.exports = sanitize;