Browse Source

switched structured query tests away from fixtures

pull/1021/head
Stephen Hess 7 years ago
parent
commit
02cfa36d24
  1. 8
      query/structured_geocoding.js
  2. 59
      test/unit/fixture/structured_geocoding/boundary_country.json
  3. 859
      test/unit/fixture/structured_geocoding/fallback.json
  4. 62
      test/unit/fixture/structured_geocoding/linguistic_bbox.json
  5. 65
      test/unit/fixture/structured_geocoding/linguistic_focus.json
  6. 76
      test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json
  7. 65
      test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json
  8. 51
      test/unit/fixture/structured_geocoding/linguistic_only.json
  9. 51
      test/unit/fixture/structured_geocoding/linguistic_viewport.json
  10. 51
      test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json
  11. 60
      test/unit/fixture/structured_geocoding/postalcode_only.js
  12. 52
      test/unit/fixture/structured_geocoding/with_source_filtering.json
  13. 663
      test/unit/query/structured_geocoding.js

8
query/structured_geocoding.js

@ -1,4 +1,4 @@
var peliasQuery = require('pelias-query'), const peliasQuery = require('pelias-query'),
defaults = require('./search_defaults'), defaults = require('./search_defaults'),
textParser = require('./text_parser'), textParser = require('./text_parser'),
check = require('check-types'); check = require('check-types');
@ -6,7 +6,7 @@ var peliasQuery = require('pelias-query'),
//------------------------------ //------------------------------
// general-purpose search query // general-purpose search query
//------------------------------ //------------------------------
var structuredQuery = new peliasQuery.layout.StructuredFallbackQuery(); const structuredQuery = new peliasQuery.layout.StructuredFallbackQuery();
// scoring boost // scoring boost
structuredQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) ); structuredQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) );
@ -29,7 +29,7 @@ structuredQuery.filter( peliasQuery.view.categories );
**/ **/
function generateQuery( clean ){ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); const vs = new peliasQuery.Vars( defaults );
// input text // input text
vs.var( 'input:name', clean.text ); vs.var( 'input:name', clean.text );
@ -95,7 +95,7 @@ function generateQuery( clean ){
textParser( clean.parsed_text, vs ); textParser( clean.parsed_text, vs );
} }
var q = getQuery(vs); const q = getQuery(vs);
// console.log(JSON.stringify(q.body, null, 2)); // console.log(JSON.stringify(q.body, null, 2));

59
test/unit/fixture/structured_geocoding/boundary_country.json

@ -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
}

859
test/unit/fixture/structured_geocoding/fallback.json

@ -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
}

62
test/unit/fixture/structured_geocoding/linguistic_bbox.json

@ -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
}

65
test/unit/fixture/structured_geocoding/linguistic_focus.json

@ -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
}

76
test/unit/fixture/structured_geocoding/linguistic_focus_bbox.json

@ -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
}

65
test/unit/fixture/structured_geocoding/linguistic_focus_null_island.json

@ -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
}

51
test/unit/fixture/structured_geocoding/linguistic_only.json

@ -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
}

51
test/unit/fixture/structured_geocoding/linguistic_viewport.json

@ -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
}

51
test/unit/fixture/structured_geocoding/linguistic_viewport_min_diagonal.json

@ -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
}

60
test/unit/fixture/structured_geocoding/postalcode_only.js

@ -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'
]
};

52
test/unit/fixture/structured_geocoding/with_source_filtering.json

@ -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
}

663
test/unit/query/structured_geocoding.js

@ -1,253 +1,606 @@
var generate = require('../../../query/structured_geocoding'); const generate = require('../../../query/structured_geocoding');
var fs = require('fs'); 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 = {};
module.exports.tests.interface = function(test, common) { module.exports.tests.interface = (test, common) => {
test('valid interface', function(t) { test('valid interface', t => {
t.equal(typeof generate, 'function', 'valid function'); t.equal(typeof generate, 'function', 'valid function');
t.end(); t.end();
}); });
}; };
module.exports.tests.query = function(test, common) { module.exports.tests.query = (test, common) => {
test('valid search + focus + bbox', function(t) { test('base no frills', t => {
var clean = { const clean = {
parsed_text: { text: 'text value',
}, sources: 'sources value',
text: 'test', layers: 'layers value'
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']
}; };
var query = generate(clean); 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'
]);
var compiled = JSON.parse( JSON.stringify( query ) ); t.end();
var expected = require('../fixture/structured_geocoding/linguistic_focus_bbox'); });
t.deepEqual(compiled.type, 'fallback', 'query type set'); test('clean.parsed_text and vs should be passed to textParser', t => {
t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox'); 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_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(); t.end();
}); });
test('valid search + bbox', function(t) {
var clean = {
parsed_text: {
},
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']
}; };
var query = generate(clean); 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 compiled = JSON.parse( JSON.stringify( query ) ); const query = proxyquire('../../../query/structured_geocoding', {
var expected = require('../fixture/structured_geocoding/linguistic_bbox'); '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.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(); t.end();
}); });
test('valid lingustic-only search', function(t) {
var clean = {
parsed_text: {
},
text: 'test', querySize: 10,
layers: ['test']
}; };
var query = generate(clean); 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 compiled = JSON.parse( JSON.stringify( query ) ); const query = proxyquire('../../../query/structured_geocoding', {
var expected = require('../fixture/structured_geocoding/linguistic_only'); '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('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(); t.end();
}); });
test('search search + focus', function(t) { test('missing focus.point.lon shouldn\'t set focus:point:lat/lon', t => {
var clean = { const clean = {
parsed_text: { text: 'text value',
}, sources: 'sources value',
text: 'test', querySize: 10, layers: 'layers value',
'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622, 'focus.point.lat': 12.121212
layers: ['test']
}; };
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 ) ); t.notOk(query.body.vs.isset('focus:point:lat'));
var expected = require('../fixture/structured_geocoding/linguistic_focus'); 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(); t.end();
}); });
test('search search + viewport', function(t) { test('focus.point.lat/lon should set focus:point:lat/lon', t => {
var clean = { const clean = {
parsed_text: { text: 'text value',
}, sources: 'sources value',
text: 'test', querySize: 10, layers: 'layers value',
'focus.viewport.min_lat': 28.49136, 'focus.point.lat': 12.121212,
'focus.viewport.max_lat': 30.49136, 'focus.point.lon': 21.212121
'focus.viewport.min_lon': -87.50622,
'focus.viewport.max_lon': -77.50622,
layers: ['test']
}; };
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 ) ); t.equals(query.body.vs.var('focus:point:lat').toString(), 12.121212);
var expected = require('../fixture/structured_geocoding/linguistic_viewport'); 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(); 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']
}; };
var query = generate(clean); 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 compiled = JSON.parse( JSON.stringify( query ) ); const query = proxyquire('../../../query/structured_geocoding', {
var expected = require('../fixture/structured_geocoding/linguistic_viewport_min_diagonal'); '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.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'valid search query');
t.end(); t.end();
}); });
test('search search + focus on null island', function(t) { test('missing boundary.rect.max_lat shouldn\'t set boundary:rect fields', t => {
var clean = { const clean = {
parsed_text: { 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
}, },
text: 'test', querySize: 10, view: views,
'focus.point.lat': 0, 'focus.point.lon': 0, Vars: require('pelias-query').Vars
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 ) ); t.notOk(query.body.vs.isset('boundary:rect:top'));
var expected = require('../fixture/structured_geocoding/linguistic_focus_null_island'); 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(); t.end();
}); });
test('parsed_text with all fields should use FallbackQuery', function(t) { test('missing boundary.rect.max_lon shouldn\'t set boundary:rect fields', t => {
var clean = { const clean = {
parsed_text: { text: 'text value',
query: 'query value', sources: 'sources value',
category: 'category value', layers: 'layers value',
number: 'number value', 'boundary.rect.min_lat': 12.121212,
street: 'street value', 'boundary.rect.max_lat': 13.131313,
neighbourhood: 'neighbourhood value', 'boundary.rect.min_lon': 21.212121
borough: 'borough value', };
postalcode: 'postalcode value',
city: 'city value', const query = proxyquire('../../../query/structured_geocoding', {
county: 'county value', 'pelias-query': {
state: 'state value', layout: {
country: 'country value' 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)); t.equals(query.body.vs.var('boundary:rect:top').toString(), 13.131313);
var expected = require('../fixture/structured_geocoding/fallback'); 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(); t.end();
}); });
test('parsed_text with all fields should use FallbackQuery', function(t) { };
var clean = {
parsed_text: { module.exports.tests.boundary_circle = (test, common) => {
postalcode: 'postalcode value' 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)); t.notOk(query.body.vs.isset('boundary:circle:lat'));
var expected = require('../fixture/structured_geocoding/postalcode_only'); 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(); t.end();
}); });
test('valid boundary.country search', function(t) { test('missing boundary.circle.radius should set lat/lon but not radius', t => {
var clean = { const clean = {
parsed_text: { 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, './search_defaults': { },
layers: ['test'], './text_parser': () => {
'boundary.country': 'ABC' 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 ) ); t.equals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212);
var expected = require('../fixture/structured_geocoding/boundary_country'); 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(); t.end();
}); });
test('valid sources filter', function(t) { test('missing boundary.circle.lat/lon but existing boundary.circle.radius should not set any', t => {
var clean = { const clean = {
parsed_text: { text: 'text value',
sources: 'sources value',
layers: 'layers value',
'boundary.circle.radius': 17
};
const query = proxyquire('../../../query/structured_geocoding', {
'pelias-query': {
layout: {
StructuredFallbackQuery: MockQuery
}, },
'text': 'test', view: views,
'sources': ['test_source'] 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();
});
}; };
var query = generate(clean); 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 compiled = JSON.parse( JSON.stringify( query ) ); const query = proxyquire('../../../query/structured_geocoding', {
var expected = require('../fixture/structured_geocoding/with_source_filtering'); '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.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(); t.end();
}); });
}; };
module.exports.all = function (tape, common) { module.exports.all = (tape, common) => {
function test(name, testFunction) { 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 ){ for( var testCase in module.exports.tests ){

Loading…
Cancel
Save