From 02cfa36d2485d4165f84e12e9618271413c08c0e Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 10 Oct 2017 16:20:01 -0400 Subject: [PATCH 1/3] switched structured query tests away from fixtures --- query/structured_geocoding.js | 14 +- .../boundary_country.json | 59 -- .../structured_geocoding/fallback.json | 859 ------------------ .../structured_geocoding/linguistic_bbox.json | 62 -- .../linguistic_focus.json | 65 -- .../linguistic_focus_bbox.json | 76 -- .../linguistic_focus_null_island.json | 65 -- .../structured_geocoding/linguistic_only.json | 51 -- .../linguistic_viewport.json | 51 -- .../linguistic_viewport_min_diagonal.json | 51 -- .../structured_geocoding/postalcode_only.js | 60 -- .../with_source_filtering.json | 52 -- test/unit/query/structured_geocoding.js | 663 ++++++++++---- 13 files changed, 515 insertions(+), 1613 deletions(-) delete mode 100644 test/unit/fixture/structured_geocoding/boundary_country.json delete mode 100644 test/unit/fixture/structured_geocoding/fallback.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_bbox.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_focus.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_only.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_viewport.json delete mode 100644 test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json delete mode 100644 test/unit/fixture/structured_geocoding/postalcode_only.js delete mode 100644 test/unit/fixture/structured_geocoding/with_source_filtering.json diff --git a/query/structured_geocoding.js b/query/structured_geocoding.js index a69f42bb..317caba1 100644 --- a/query/structured_geocoding.js +++ b/query/structured_geocoding.js @@ -1,12 +1,12 @@ -var peliasQuery = require('pelias-query'), - defaults = require('./search_defaults'), - textParser = require('./text_parser'), - check = require('check-types'); +const peliasQuery = require('pelias-query'), + defaults = require('./search_defaults'), + textParser = require('./text_parser'), + check = require('check-types'); //------------------------------ // general-purpose search query //------------------------------ -var structuredQuery = new peliasQuery.layout.StructuredFallbackQuery(); +const structuredQuery = new peliasQuery.layout.StructuredFallbackQuery(); // scoring boost structuredQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) ); @@ -29,7 +29,7 @@ structuredQuery.filter( peliasQuery.view.categories ); **/ function generateQuery( clean ){ - var vs = new peliasQuery.Vars( defaults ); + const vs = new peliasQuery.Vars( defaults ); // input text vs.var( 'input:name', clean.text ); @@ -95,7 +95,7 @@ function generateQuery( clean ){ textParser( clean.parsed_text, vs ); } - var q = getQuery(vs); + const q = getQuery(vs); // console.log(JSON.stringify(q.body, null, 2)); diff --git a/test/unit/fixture/structured_geocoding/boundary_country.json b/test/unit/fixture/structured_geocoding/boundary_country.json deleted file mode 100644 index edff5d63..00000000 --- a/test/unit/fixture/structured_geocoding/boundary_country.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "match": { - "parent.country_a": { - "analyzer": "standard", - "query": "ABC" - } - } - }, - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/fallback.json b/test/unit/fixture/structured_geocoding/fallback.json deleted file mode 100644 index 7b737ffd..00000000 --- a/test/unit/fixture/structured_geocoding/fallback.json +++ /dev/null @@ -1,859 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "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" - ] - } - } - ], - "filter": { - "term": { - "layer": "venue" - } - } - } - }, - { - "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 - } - }, - { - "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.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.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" - ] - } - } - ], - "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.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.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, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 20, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_bbox.json b/test/unit/fixture/structured_geocoding/linguistic_bbox.json deleted file mode 100644 index 94acc81d..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_bbox.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "geo_bounding_box": { - "type": "indexed", - "center_point": { - "top": 11.51, - "right": -61.84, - "bottom": 47.47, - "left": -103.16 - } - } - }, - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus.json b/test/unit/fixture/structured_geocoding/linguistic_focus.json deleted file mode 100644 index 0bb126d1..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_focus.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "weight": 2, - "linear": { - "center_point": { - "origin": { - "lat": 29.49136, - "lon": -82.50622 - }, - "offset": "0km", - "scale": "50km", - "decay": 0.5 - } - } - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json b/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json deleted file mode 100644 index 5b98f11f..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "geo_bounding_box": { - "type": "indexed", - "center_point": { - "top": 11.51, - "right": -61.84, - "bottom": 47.47, - "left": -103.16 - } - } - }, - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "weight": 2, - "linear": { - "center_point": { - "origin": { - "lat": 29.49136, - "lon": -82.50622 - }, - "offset": "0km", - "scale": "50km", - "decay": 0.5 - } - } - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json b/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json deleted file mode 100644 index d8723845..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "weight": 2, - "linear": { - "center_point": { - "origin": { - "lat": 0, - "lon": 0 - }, - "offset": "0km", - "scale": "50km", - "decay": 0.5 - } - } - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_only.json b/test/unit/fixture/structured_geocoding/linguistic_only.json deleted file mode 100644 index 4de54360..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_only.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_viewport.json b/test/unit/fixture/structured_geocoding/linguistic_viewport.json deleted file mode 100644 index 4de54360..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_viewport.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json b/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json deleted file mode 100644 index 4de54360..00000000 --- a/test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [], - "filter": { - "bool": { - "must": [ - { - "terms": { - "layer": [ - "test" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 10, - "track_scores": true -} diff --git a/test/unit/fixture/structured_geocoding/postalcode_only.js b/test/unit/fixture/structured_geocoding/postalcode_only.js deleted file mode 100644 index 2eb10d30..00000000 --- a/test/unit/fixture/structured_geocoding/postalcode_only.js +++ /dev/null @@ -1,60 +0,0 @@ -module.exports = { - 'query': { - 'function_score': { - 'query': { - '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' - } - } - } - } - ] - } - }, - 'max_boost': 20, - 'functions': [ - { - 'field_value_factor': { - 'modifier': 'log1p', - 'field': 'popularity', - 'missing': 1 - }, - 'weight': 1 - }, - { - 'field_value_factor': { - 'modifier': 'log1p', - 'field': 'population', - 'missing': 1 - }, - 'weight': 2 - } - ], - 'score_mode': 'avg', - 'boost_mode': 'multiply' - } - }, - 'size': 20, - 'track_scores': true, - 'sort': [ - '_score' - ] -}; diff --git a/test/unit/fixture/structured_geocoding/with_source_filtering.json b/test/unit/fixture/structured_geocoding/with_source_filtering.json deleted file mode 100644 index 77e4fb87..00000000 --- a/test/unit/fixture/structured_geocoding/with_source_filtering.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "query": { - "function_score": { - "query": { - "bool": { - "minimum_should_match": 1, - "should": [ - ], - "filter": { - "bool": { - "must": [ - { - "terms": { - "source": [ - "test_source" - ] - } - } - ] - } - } - } - }, - "max_boost": 20, - "functions": [ - { - "field_value_factor": { - "modifier": "log1p", - "field": "popularity", - "missing": 1 - }, - "weight": 1 - }, - { - "field_value_factor": { - "modifier": "log1p", - "field": "population", - "missing": 1 - }, - "weight": 2 - } - ], - "score_mode": "avg", - "boost_mode": "multiply" - } - }, - "sort": [ - "_score" - ], - "size": 20, - "track_scores": true -} diff --git a/test/unit/query/structured_geocoding.js b/test/unit/query/structured_geocoding.js index d93a03aa..3fef87f0 100644 --- a/test/unit/query/structured_geocoding.js +++ b/test/unit/query/structured_geocoding.js @@ -1,253 +1,606 @@ -var generate = require('../../../query/structured_geocoding'); -var fs = require('fs'); +const generate = require('../../../query/structured_geocoding'); +const _ = require('lodash'); +const proxyquire = require('proxyquire').noCallThru(); +const MockQuery = require('./MockQuery'); + +// helper for canned views +const views = { + focus_only_function: () => 'focus_only_function view', + popularity_only_function: 'popularity_only_function view', + population_only_function: 'population_only_function view', + boundary_country: 'boundary_country view', + boundary_circle: 'boundary_circle view', + boundary_rect: 'boundary_rect view', + sources: 'sources view', + layers: 'layers view', + categories: 'categories view' +}; module.exports.tests = {}; -module.exports.tests.interface = function(test, common) { - test('valid interface', function(t) { +module.exports.tests.interface = (test, common) => { + test('valid interface', t => { t.equal(typeof generate, 'function', 'valid function'); t.end(); }); }; -module.exports.tests.query = function(test, common) { - test('valid search + focus + bbox', function(t) { - var clean = { - parsed_text: { - }, - text: 'test', - querySize: 10, - 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622, - 'boundary.rect.min_lat': 47.47, - 'boundary.rect.max_lon': -61.84, - 'boundary.rect.max_lat': 11.51, - 'boundary.rect.min_lon': -103.16, - layers: ['test'] +module.exports.tests.query = (test, common) => { + test('base no frills', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value' }; - var query = generate(clean); - - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_focus_bbox'); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { + default_parameter_1: 'first default parameter', + default_parameter_2: 'second default parameter' + }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); + + t.equals(query.type, 'fallback', 'query type set'); + t.equals(query.body.vs.var('input:name').toString(), 'text value'); + t.equals(query.body.vs.var('sources').toString(), 'sources value'); + t.equals(query.body.vs.var('layers').toString(), 'layers value'); + t.deepEquals(query.body.vs.var('default_parameter_1').toString(), 'first default parameter'); + t.deepEquals(query.body.vs.var('default_parameter_2').toString(), 'second default parameter'); + t.notOk(query.body.vs.isset('size')); + t.notOk(query.body.vs.isset('focus:point:lat')); + t.notOk(query.body.vs.isset('focus:point:lon')); + t.notOk(query.body.vs.isset('boundary:rect:top')); + t.notOk(query.body.vs.isset('boundary:rect:right')); + t.notOk(query.body.vs.isset('boundary:rect:bottom')); + t.notOk(query.body.vs.isset('boundary:rect:left')); + t.notOk(query.body.vs.isset('boundary:circle:lat')); + t.notOk(query.body.vs.isset('boundary:circle:lon')); + t.notOk(query.body.vs.isset('boundary:circle:radius')); + t.notOk(query.body.vs.isset('boundary:country')); + + t.deepEquals(query.body.score_functions, [ + 'focus_only_function view', + 'popularity_only_function view', + 'population_only_function view' + ]); + + t.deepEquals(query.body.filter_functions, [ + 'boundary_country view', + 'boundary_circle view', + 'boundary_rect view', + 'sources view', + 'layers view', + 'categories view' + ]); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox'); t.end(); }); - test('valid search + bbox', function(t) { - var clean = { - parsed_text: { + test('clean.parsed_text and vs should be passed to textParser', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + parsed_text: 'parsed_text value' + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { + default_parameter_1: 'first default parameter', + default_parameter_2: 'second default parameter' }, - text: 'test', - querySize: 10, - 'boundary.rect.min_lat': 47.47, - 'boundary.rect.max_lon': -61.84, - 'boundary.rect.max_lat': 11.51, - 'boundary.rect.min_lon': -103.16, - layers: ['test'] + './text_parser': (parsed_text, vs) => { + vs.var('text_parser:value', 'this value populated by text_parser'); + } + })(clean); + + t.deepEquals(query.body.vs.var('text_parser:value').toString(), 'this value populated by text_parser'); + t.end(); + + }); + +}; + +module.exports.tests.query_size = (test, common) => { + test('size should be set when querySize is available', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + querySize: 17 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_bbox'); + t.equals(query.body.vs.var('size').toString(), 17); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_bbox'); t.end(); + }); - test('valid lingustic-only search', function(t) { - var clean = { - parsed_text: { - }, - text: 'test', querySize: 10, - layers: ['test'] +}; + +module.exports.tests.focus_point_lat_lon = (test, common) => { + test('missing focus.point.lat shouldn\'t set focus:point:lat/lon', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'focus.point.lon': 21.212121 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_only'); + t.notOk(query.body.vs.isset('focus:point:lat')); + t.notOk(query.body.vs.isset('focus:point:lon')); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_only'); t.end(); + }); - test('search search + focus', function(t) { - var clean = { - parsed_text: { - }, - text: 'test', querySize: 10, - 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622, - layers: ['test'] + test('missing focus.point.lon shouldn\'t set focus:point:lat/lon', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'focus.point.lat': 12.121212 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_focus'); + t.notOk(query.body.vs.isset('focus:point:lat')); + t.notOk(query.body.vs.isset('focus:point:lon')); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_focus'); t.end(); + }); - test('search search + viewport', function(t) { - var clean = { - parsed_text: { - }, - text: 'test', querySize: 10, - 'focus.viewport.min_lat': 28.49136, - 'focus.viewport.max_lat': 30.49136, - 'focus.viewport.min_lon': -87.50622, - 'focus.viewport.max_lon': -77.50622, - layers: ['test'] + test('focus.point.lat/lon should set focus:point:lat/lon', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'focus.point.lat': 12.121212, + 'focus.point.lon': 21.212121 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_viewport'); + t.equals(query.body.vs.var('focus:point:lat').toString(), 12.121212); + t.equals(query.body.vs.var('focus:point:lon').toString(), 21.212121); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_viewport'); t.end(); + }); - // viewport scale sizing currently disabled. - // ref: https://github.com/pelias/api/pull/388 - test('search with viewport diagonal < 1km should set scale to 1km', function(t) { - var clean = { - parsed_text: { - }, - text: 'test', querySize: 10, - 'focus.viewport.min_lat': 28.49135, - 'focus.viewport.max_lat': 28.49137, - 'focus.viewport.min_lon': -87.50622, - 'focus.viewport.max_lon': -87.50624, - layers: ['test'] +}; + +module.exports.tests.boundary_rect = (test, common) => { + test('missing boundary.rect.min_lat shouldn\'t set boundary:rect fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.rect.max_lat': 13.131313, + 'boundary.rect.min_lon': 21.212121, + 'boundary.rect.max_lon': 31.313131 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_viewport_min_diagonal'); + t.notOk(query.body.vs.isset('boundary:rect:top')); + t.notOk(query.body.vs.isset('boundary:rect:right')); + t.notOk(query.body.vs.isset('boundary:rect:bottom')); + t.notOk(query.body.vs.isset('boundary:rect:left')); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'valid search query'); t.end(); + }); - test('search search + focus on null island', function(t) { - var clean = { - parsed_text: { + test('missing boundary.rect.max_lat shouldn\'t set boundary:rect fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.rect.min_lat': 12.121212, + 'boundary.rect.min_lon': 21.212121, + 'boundary.rect.max_lon': 31.313131 + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars }, - text: 'test', querySize: 10, - 'focus.point.lat': 0, 'focus.point.lon': 0, - layers: ['test'] + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); + + t.notOk(query.body.vs.isset('boundary:rect:top')); + t.notOk(query.body.vs.isset('boundary:rect:right')); + t.notOk(query.body.vs.isset('boundary:rect:bottom')); + t.notOk(query.body.vs.isset('boundary:rect:left')); + + t.end(); + + }); + + test('missing boundary.rect.min_lon shouldn\'t set boundary:rect fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.rect.min_lat': 12.121212, + 'boundary.rect.max_lat': 13.131313, + 'boundary.rect.max_lon': 31.313131 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/linguistic_focus_null_island'); + t.notOk(query.body.vs.isset('boundary:rect:top')); + t.notOk(query.body.vs.isset('boundary:rect:right')); + t.notOk(query.body.vs.isset('boundary:rect:bottom')); + t.notOk(query.body.vs.isset('boundary:rect:left')); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search_linguistic_focus_null_island'); t.end(); + }); - test('parsed_text with all fields should use FallbackQuery', function(t) { - var clean = { - parsed_text: { - query: 'query value', - category: 'category value', - number: 'number value', - street: 'street value', - neighbourhood: 'neighbourhood value', - borough: 'borough value', - postalcode: 'postalcode value', - city: 'city value', - county: 'county value', - state: 'state value', - country: 'country value' + test('missing boundary.rect.max_lon shouldn\'t set boundary:rect fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.rect.min_lat': 12.121212, + 'boundary.rect.max_lat': 13.131313, + 'boundary.rect.min_lon': 21.212121 + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); } + })(clean); + + t.notOk(query.body.vs.isset('boundary:rect:top')); + t.notOk(query.body.vs.isset('boundary:rect:right')); + t.notOk(query.body.vs.isset('boundary:rect:bottom')); + t.notOk(query.body.vs.isset('boundary:rect:left')); + + t.end(); + + }); + + test('focus.point.lat/lon should set focus:point:lat/lon', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.rect.min_lat': 12.121212, + 'boundary.rect.max_lat': 13.131313, + 'boundary.rect.min_lon': 21.212121, + 'boundary.rect.max_lon': 31.313131 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse(JSON.stringify(query)); - var expected = require('../fixture/structured_geocoding/fallback'); + t.equals(query.body.vs.var('boundary:rect:top').toString(), 13.131313); + t.equals(query.body.vs.var('boundary:rect:right').toString(), 31.313131); + t.equals(query.body.vs.var('boundary:rect:bottom').toString(), 12.121212); + t.equals(query.body.vs.var('boundary:rect:left').toString(), 21.212121); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'fallbackQuery'); t.end(); }); - test('parsed_text with all fields should use FallbackQuery', function(t) { - var clean = { - parsed_text: { - postalcode: 'postalcode value' +}; + +module.exports.tests.boundary_circle = (test, common) => { + test('missing boundary.circle.lat shouldn\'t set boundary:circle fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.circle.lon': 21.212121, + 'boundary.circle.radius': 17 + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); } + })(clean); + + t.notOk(query.body.vs.isset('boundary:circle:lat')); + t.notOk(query.body.vs.isset('boundary:circle:lon')); + t.notOk(query.body.vs.isset('boundary:circle:radius')); + + t.end(); + + }); + + test('missing boundary.circle.lon shouldn\'t set boundary:circle fields', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.circle.lat': 12.121212, + 'boundary.circle.radius': 17 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse(JSON.stringify(query)); - var expected = require('../fixture/structured_geocoding/postalcode_only'); + t.notOk(query.body.vs.isset('boundary:circle:lat')); + t.notOk(query.body.vs.isset('boundary:circle:lon')); + t.notOk(query.body.vs.isset('boundary:circle:radius')); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'structured postalcode only'); t.end(); }); - test('valid boundary.country search', function(t) { - var clean = { - parsed_text: { + test('missing boundary.circle.radius should set lat/lon but not radius', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.circle.lat': 12.121212, + 'boundary.circle.lon': 21.212121 + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars }, - text: 'test', querySize: 10, - layers: ['test'], - 'boundary.country': 'ABC' + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); + + t.equals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212); + t.equals(query.body.vs.var('boundary:circle:lon').toString(), 21.212121); + t.notOk(query.body.vs.isset('boundary:circle:radius')); + + t.end(); + + }); + + test('boundary.circle.* should set lat/lon/radius with last rounded and in kilometers', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.circle.lat': 12.121212, + 'boundary.circle.lon': 21.212121, + 'boundary.circle.radius': 17.5 }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/boundary_country'); + t.equals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212); + t.equals(query.body.vs.var('boundary:circle:lon').toString(), 21.212121); + t.equals(query.body.vs.var('boundary:circle:radius').toString(), '18km'); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search: valid boundary.country query'); t.end(); + }); - test('valid sources filter', function(t) { - var clean = { - parsed_text: { + test('missing boundary.circle.lat/lon but existing boundary.circle.radius should not set any', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.circle.radius': 17 + }; + + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars }, - 'text': 'test', - 'sources': ['test_source'] + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); + + t.notOk(query.body.vs.isset('boundary:circle:lat')); + t.notOk(query.body.vs.isset('boundary:circle:lon')); + t.notOk(query.body.vs.isset('boundary:circle:radius')); + + t.end(); + + }); + +}; + +module.exports.tests.boundary_country = (test, common) => { + test('boundary.country available shoul set boundary:country', t => { + const clean = { + text: 'text value', + sources: 'sources value', + layers: 'layers value', + 'boundary.country': 'boundary country value' }; - var query = generate(clean); + const query = proxyquire('../../../query/structured_geocoding', { + 'pelias-query': { + layout: { + StructuredFallbackQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + }, + './search_defaults': { }, + './text_parser': () => { + t.fail('text_parser should not have been called'); + } + })(clean); - var compiled = JSON.parse( JSON.stringify( query ) ); - var expected = require('../fixture/structured_geocoding/with_source_filtering'); + t.equals(query.body.vs.var('boundary:country').toString(), 'boundary country value'); - t.deepEqual(compiled.type, 'fallback', 'query type set'); - t.deepEqual(compiled.body, expected, 'search: valid search query with source filtering'); t.end(); + }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('structured_geocoding query ' + name, testFunction); + return tape(`structured_geocoding query ${name}`, testFunction); } for( var testCase in module.exports.tests ){ From 5d7a0bfd1c3a42876b9c6149b6c181affe2bf71a Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 11 Oct 2017 21:14:44 +0000 Subject: [PATCH 2/3] fix(package): update pelias-text-analyzer to version 1.9.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd567c54..9fc08508 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "pelias-model": "5.1.0", "pelias-query": "9.1.0", "pelias-sorting": "1.0.1", - "pelias-text-analyzer": "1.9.2", + "pelias-text-analyzer": "1.9.5", "predicates": "^1.0.1", "retry": "^0.10.1", "stats-lite": "^2.0.4", From 2ec1af485603ed84c04251c99edc692a0a8f2631 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 14 Oct 2017 15:38:58 +0000 Subject: [PATCH 3/3] fix(package): update joi to version 12.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dbd2409a..455e8371 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "geolib": "^2.0.18", "iso-639-3": "^1.0.0", "iso3166-1": "^0.3.0", - "joi": "^11.0.1", + "joi": "^12.0.0", "locale": "^0.1.0", "lodash": "^4.17.4", "markdown": "0.5.0",