Browse Source

Fix all unit tests

pull/426/head
Diana Shkolnikov 9 years ago committed by Julian Simioni
parent
commit
af8044ef29
  1. 2
      helper/labelGenerator.js
  2. 16
      test/unit/controller/search.js
  3. 14
      test/unit/fixture/autocomplete_linguistic_with_admin.js
  4. 38
      test/unit/fixture/dedupe_elasticsearch_nonascii_results.js
  5. 190
      test/unit/fixture/dedupe_elasticsearch_results.js
  6. 2
      test/unit/fixture/reverse_with_boundary_country.js
  7. 2
      test/unit/fixture/search_boundary_country.js
  8. 48
      test/unit/fixture/search_full_address.js
  9. 38
      test/unit/fixture/search_partial_address.js
  10. 38
      test/unit/fixture/search_regions_address.js
  11. 4
      test/unit/helper/labelGenerator_SGP.js
  12. 4
      test/unit/helper/labelGenerator_SWE.js
  13. 8
      test/unit/mock/backend.js
  14. 17
      test/unit/query/search.js
  15. 12
      test/unit/sanitiser/_layers.js
  16. 2
      test/unit/sanitiser/search.js
  17. 4
      test/unit/service/mget.js
  18. 4
      test/unit/service/search.js

2
helper/labelGenerator.js

@ -52,6 +52,6 @@ function getInitialLabel(record) {
return [];
}
return [record.name.default];
return [record.name];
}

16
test/unit/controller/search.js

@ -50,9 +50,11 @@ module.exports.tests.functional_success = function(test, common) {
_id: 'myid1',
_score: 10,
_type: 'mytype1',
admin0: 'country1',
admin1: 'state1',
admin2: 'city1',
parent: {
country: 'country1',
region: 'state1',
county: 'city1'
},
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
value: 1
@ -61,9 +63,11 @@ module.exports.tests.functional_success = function(test, common) {
_id: 'myid2',
_score: 20,
_type: 'mytype2',
admin0: 'country2',
admin1: 'state2',
admin2: 'city2',
parent: {
country: 'country2',
region: 'state2',
county: 'city2'
},
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
value: 2

14
test/unit/fixture/autocomplete_linguistic_with_admin.js

@ -20,7 +20,7 @@ module.exports = {
'should': [
{
'match': {
'admin0': {
'parent.country': {
'analyzer': 'peliasAdmin',
'boost': 800,
'query': 'three'
@ -29,7 +29,7 @@ module.exports = {
},
{
'match': {
'admin1': {
'parent.region': {
'analyzer': 'peliasAdmin',
'boost': 600,
'query': 'three'
@ -38,7 +38,7 @@ module.exports = {
},
{
'match': {
'admin1_abbr': {
'parent.region_a': {
'analyzer': 'peliasAdmin',
'boost': 600,
'query': 'three'
@ -47,7 +47,7 @@ module.exports = {
},
{
'match': {
'admin2': {
'parent.county': {
'analyzer': 'peliasAdmin',
'boost': 400,
'query': 'three'
@ -56,7 +56,7 @@ module.exports = {
},
{
'match': {
'local_admin': {
'parent.localadmin': {
'analyzer': 'peliasAdmin',
'boost': 200,
'query': 'three'
@ -65,7 +65,7 @@ module.exports = {
},
{
'match': {
'locality': {
'parent.locality': {
'analyzer': 'peliasAdmin',
'boost': 200,
'query': 'three'
@ -74,7 +74,7 @@ module.exports = {
},
{
'match': {
'neighborhood': {
'parent.neighbourhood': {
'analyzer': 'peliasAdmin',
'boost': 200,
'query': 'three'

38
test/unit/fixture/dedupe_elasticsearch_nonascii_results.js

@ -7,9 +7,11 @@ module.exports = [
'name': {
'default': '万里长城万里长城'
},
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing',
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing'
},
'confidence': 0.733
},
{
@ -20,9 +22,11 @@ module.exports = [
'name': {
'default': '万里长城'
},
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing',
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing'
},
'confidence': 0.733
},
{
@ -33,12 +37,14 @@ module.exports = [
'name': {
'default': '万里花'
},
'country_a': 'JPN',
'country': 'Japan',
'region': 'Tokyo',
'county': '豊島区',
'locality': 'Tokyo',
'neighbourhood': '2丁目',
'parent': {
'country_a': 'JPN',
'country': 'Japan',
'region': 'Tokyo',
'county': '豊島区',
'locality': 'Tokyo',
'neighbourhood': '2丁目'
},
'confidence': 0.646
},
{
@ -53,9 +59,11 @@ module.exports = [
'street': 'S308',
'postalcode': '312044'
},
'country_a': 'CHN',
'country': 'China',
'region': 'Zhejiang',
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Zhejiang'
},
'confidence': 0.646
}
];

190
test/unit/fixture/dedupe_elasticsearch_results.js

@ -5,17 +5,19 @@ module.exports = [
'lat': 40.039265
},
'address': {},
'local_admin': 'East Lampeter',
'admin1_abbr': 'PA',
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': {
'default': 'East Lampeter High School'
},
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [
'education'
],
@ -30,17 +32,19 @@ module.exports = [
'lat': 40.039265
},
'address': {},
'local_admin': 'East Lampeter',
'admin1_abbr': 'PA',
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': {
'default': 'East Lampeter, High-School'
},
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [
'education'
],
@ -55,17 +59,19 @@ module.exports = [
'lat': 39.99288
},
'address': {},
'local_admin': 'West Lampeter',
'admin1_abbr': 'PA',
'parent': {
'localadmin': 'West Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills'
},
'name': {
'default': 'Lampeter-Strasburg High School'
},
'admin1': 'Pennsylvania',
'locality': 'Lampeter',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Wheatland Mills',
'category': [
'education'
],
@ -80,17 +86,19 @@ module.exports = [
'lat': 40.03927
},
'address': {},
'local_admin': 'East Lampeter',
'admin1_abbr': 'PA',
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': {
'default': 'East Lampeter High School'
},
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [
'education'
],
@ -105,17 +113,19 @@ module.exports = [
'lat': 39.992877
},
'address': {},
'local_admin': 'West Lampeter',
'admin1_abbr': 'PA',
'parent': {
'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills',
'localadmin': 'West Lampeter',
'region_a': 'PA'
},
'name': {
'default': 'Lampeter-Strasburg High School'
},
'admin1': 'Pennsylvania',
'locality': 'Lampeter',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Wheatland Mills',
'category': [
'education'
],
@ -130,17 +140,19 @@ module.exports = [
'lat': 40.038987
},
'address': {},
'local_admin': 'East Lampeter',
'admin1_abbr': 'PA',
'parent': {
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
},
'name': {
'default': 'East Lampeter School'
},
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [
'education'
],
@ -155,17 +167,19 @@ module.exports = [
'lat': 40.03899
},
'address': {},
'local_admin': 'East Lampeter',
'admin1_abbr': 'PA',
'parent': {
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
},
'name': {
'default': 'East Lampeter School'
},
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [
'education'
],
@ -180,16 +194,18 @@ module.exports = [
'lat': 38.762788
},
'address': {},
'local_admin': 'Polk',
'admin1_abbr': 'MO',
'parent': {
'region': 'Missouri',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Cass County',
'country': 'United States',
'localadmin': 'Polk',
'region_a': 'MO'
},
'name': {
'default': 'Strasburg School'
},
'admin1': 'Missouri',
'locality': 'Strasburg',
'alpha3': 'USA',
'admin2': 'Cass County',
'admin0': 'United States',
'category': [
'education'
],
@ -204,16 +220,18 @@ module.exports = [
'lat': 38.98445
},
'address': {},
'admin1_abbr': 'VA',
'name': {
'default': 'Strasburg High School'
},
'admin1': 'Virginia',
'locality': 'Strasburg',
'alpha3': 'USA',
'admin2': 'Shenandoah County',
'admin0': 'United States',
'neighborhood': 'Strasburg Junction',
'parent': {
'region_a': 'VA',
'region': 'Virginia',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Shenandoah County',
'country': 'United States',
'neighbourhood': 'Strasburg Junction'
},
'category': [
'education'
],
@ -228,16 +246,18 @@ module.exports = [
'lat': 46.13427
},
'address': {},
'local_admin': 'Strasburg',
'admin1_abbr': 'ND',
'name': {
'default': 'Strasburg High School'
},
'admin1': 'North Dakota',
'locality': 'Strasburg',
'alpha3': 'USA',
'admin2': 'Emmons County',
'admin0': 'United States',
'parent': {
'localadmin': 'Strasburg',
'region_a': 'ND',
'region': 'North Dakota',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Emmons County',
'country': 'United States'
},
'category': [
'education'
],
@ -252,16 +272,18 @@ module.exports = [
'lat': 40.597578
},
'address': {},
'local_admin': 'Franklin',
'admin1_abbr': 'OH',
'name': {
'default': 'Strasburg High School'
},
'admin1': 'Ohio',
'locality': 'Strasburg',
'alpha3': 'USA',
'admin2': 'Tuscarawas County',
'admin0': 'United States',
'parent': {
'localadmin': 'Franklin',
'region_a': 'OH',
'region': 'Ohio',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Tuscarawas County',
'country': 'United States'
},
'category': [
'education'
],

2
test/unit/fixture/reverse_with_boundary_country.js

@ -8,7 +8,7 @@ module.exports = {
'must': [
{
'match': {
'alpha3': {
'parent.country_a': {
'analyzer': 'standard',
'query': 'ABC'
}

2
test/unit/fixture/search_boundary_country.js

@ -7,7 +7,7 @@ module.exports = {
'must': [
{
'match': {
'alpha3': {
'parent.country_a': {
'analyzer': 'standard',
'query': 'ABC'
}

48
test/unit/fixture/search_full_address.js

@ -109,55 +109,55 @@ module.exports = {
}
}, {
'match': {
'alpha3': {
'query': 'USA',
'boost': vs['admin:alpha3:boost'],
'analyzer': vs['admin:alpha3:analyzer']
'parent.country': {
'query': 'new york',
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'admin0': {
'query': 'new york',
'boost': vs['admin:admin0:boost'],
'analyzer': vs['admin:admin0:analyzer']
'parent.country_a': {
'query': 'USA',
'boost': vs['admin:country_a:boost'],
'analyzer': vs['admin:country_a:analyzer']
}
}
}, {
'match': {
'admin1': {
'parent.region': {
'query': 'new york',
'boost': vs['admin:admin1:boost'],
'analyzer': vs['admin:admin1:analyzer']
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'admin1_abbr': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:admin1_abbr:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer']
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'match': {
'admin2': {
'parent.county': {
'query': 'new york',
'boost': vs['admin:admin2:boost'],
'analyzer': vs['admin:admin2:analyzer']
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
}
}
}, {
'match': {
'local_admin': {
'parent.localadmin': {
'query': 'new york',
'boost': vs['admin:local_admin:boost'],
'analyzer': vs['admin:local_admin:analyzer']
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'locality': {
'parent.locality': {
'query': 'new york',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
@ -165,10 +165,10 @@ module.exports = {
}
}, {
'match': {
'neighborhood': {
'parent.neighbourhood': {
'query': 'new york',
'boost': vs['admin:neighborhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer']
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
}
}]

38
test/unit/fixture/search_partial_address.js

@ -85,47 +85,47 @@ module.exports = {
}
},{
'match': {
'admin0': {
'parent.country': {
'query': 'new york',
'boost': vs['admin:admin0:boost'],
'analyzer': vs['admin:admin0:analyzer']
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'admin1': {
'parent.region': {
'query': 'new york',
'boost': vs['admin:admin1:boost'],
'analyzer': vs['admin:admin1:analyzer']
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'admin1_abbr': {
'parent.region_a': {
'query': 'new york',
'boost': vs['admin:admin1_abbr:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer']
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'match': {
'admin2': {
'parent.county': {
'query': 'new york',
'boost': vs['admin:admin2:boost'],
'analyzer': vs['admin:admin2:analyzer']
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
}
}
}, {
'match': {
'local_admin': {
'parent.localadmin': {
'query': 'new york',
'boost': vs['admin:local_admin:boost'],
'analyzer': vs['admin:local_admin:analyzer']
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'locality': {
'parent.locality': {
'query': 'new york',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
@ -133,10 +133,10 @@ module.exports = {
}
}, {
'match': {
'neighborhood': {
'parent.neighbourhood': {
'query': 'new york',
'boost': vs['admin:neighborhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer']
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
}
}]

38
test/unit/fixture/search_regions_address.js

@ -101,47 +101,47 @@ module.exports = {
}
}, {
'match': {
'admin0': {
'parent.country': {
'query': 'manhattan',
'boost': vs['admin:admin0:boost'],
'analyzer': vs['admin:admin0:analyzer']
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'admin1': {
'parent.region': {
'query': 'manhattan',
'boost': vs['admin:admin1:boost'],
'analyzer': vs['admin:admin1:analyzer']
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'admin1_abbr': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:admin1_abbr:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer']
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'match': {
'admin2': {
'parent.county': {
'query': 'manhattan',
'boost': vs['admin:admin2:boost'],
'analyzer': vs['admin:admin2:analyzer']
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
}
}
}, {
'match': {
'local_admin': {
'parent.localadmin': {
'query': 'manhattan',
'boost': vs['admin:local_admin:boost'],
'analyzer': vs['admin:local_admin:analyzer']
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'locality': {
'parent.locality': {
'query': 'manhattan',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
@ -149,10 +149,10 @@ module.exports = {
}
}, {
'match': {
'neighborhood': {
'parent.neighbourhood': {
'query': 'manhattan',
'boost': vs['admin:neighborhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer']
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
}
}]

4
test/unit/helper/labelGenerator_SGP.js

@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.north_west_singapore = function(test, common) {
test('north west singapore', function(t) {
var doc = {
'name': { 'default': 'North West' },
'name': 'North West',
'country_a': 'SGP',
'country': 'Singapore',
'region': 'North West'
@ -28,7 +28,7 @@ module.exports.tests.north_west_singapore = function(test, common) {
module.exports.tests.singapore_mcdonalds = function(test, common) {
test('singapore_mcdonalds', function(t) {
var doc = {
'name': { 'default': 'McDonald\'s' },
'name': 'McDonald\'s',
'country_a': 'SGP',
'country': 'Singapore',
'region': 'Central Singapore',

4
test/unit/helper/labelGenerator_SWE.js

@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.skane1 = function(test, common) {
test('skåne 1', function(t) {
var doc = {
'name': { 'default': 'Malmö' },
'name': 'Malmö',
'country_a': 'SWE',
'country': 'Sweden',
'region': 'Skåne',
@ -29,7 +29,7 @@ module.exports.tests.skane1 = function(test, common) {
module.exports.tests.skane2 = function(test, common) {
test('skåne 2', function(t) {
var doc = {
'name': { 'default': 'Malmö' },
'name': 'Malmö',
'country_a': 'SWE',
'country': 'Sweden',
'region': 'Skåne',

8
test/unit/mock/backend.js

@ -15,7 +15,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1'
parent: { country: 'country1', region: 'state1', county: 'city1' }
}
}, {
_id: 'myid2',
@ -25,7 +25,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2'
parent: { country: 'country2', region: 'state2', county: 'city2' }
}
}]));
};
@ -43,7 +43,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1'
parent: { country: 'country1', region: 'state1', county: 'city1' }
}
}, {
_id: 'myid2',
@ -54,7 +54,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2'
parent: { country: 'country2', region: 'state2', county: 'city2' }
}
}]));
};

17
test/unit/query/search.js

@ -126,8 +126,7 @@ module.exports.tests.query = function(test, common) {
test('valid query with a full valid address', function(t) {
var address = '123 main st new york ny 10010 US';
var query = generate({ text: address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: parser.get_parsed_address(address),
});
@ -135,15 +134,20 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address');
t.deepEqual(compiled, expected, 'valid search query');
t.deepEqual(compiled.query.filtered.query.bool.should, expected.query.filtered.query.bool.should, 'valid boundary.country query');
[ { match: { 'phrase.default': { analyzer: 'peliasPhrase', boost: 1, query: '123 main st', slop: 2, type: 'phrase' } } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'popularity' } }, functions: [ { field_value_factor: [Object], weight: 1 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'population' } }, functions: [ { field_value_factor: [Object], weight: 2 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { match: { 'address.number': { analyzer: 'peliasHousenumber', boost: 2, query: '123' } } }, { match: { 'address.street': { analyzer: 'peliasStreet', boost: 5, query: 'main st' } } }, { match: { 'address.zip': { analyzer: 'peliasZip', boost: 20, query: '10010' } } }, { match: { 'parent.country_a': { analyzer: 'standard', boost: 5, query: 'USA' } } }, { match: { 'parent.country': { analyzer: 'peliasAdmin', boost: 4, query: 'new york' } } }, { match: { 'parent.region': { analyzer: 'peliasAdmin', boost: 3, query: 'new york' } } }, { match: { 'parent.region_a': { analyzer: 'peliasAdmin', boost: 3, query: 'NY' } } }, { match: { 'parent.county': { analyzer: 'peliasAdmin', boost: 2, query: 'new york' } } }, { match: { 'parent.localadmin': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.locality': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.neighbourhood': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } } ]
[ { match: { 'phrase.default': { analyzer: 'peliasPhrase', boost: 1, query: '123 main st', slop: 2, type: 'phrase' } } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'popularity' } }, functions: [ { field_value_factor: [Object], weight: 1 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'population' } }, functions: [ { field_value_factor: [Object], weight: 2 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { match: { 'address.number': { analyzer: 'peliasHousenumber', boost: 2, query: '123' } } }, { match: { 'address.street': { analyzer: 'peliasStreet', boost: 5, query: 'main st' } } }, { match: { 'address.zip': { analyzer: 'peliasZip', boost: 20, query: '10010' } } }, { match: { 'parent.country': { analyzer: 'peliasAdmin', boost: 4, query: 'new york' } } }, { match: { 'parent.country_a': { analyzer: 'standard', boost: 5, query: 'USA' } } }, { match: { 'parent.region': { analyzer: 'peliasAdmin', boost: 3, query: 'new york' } } }, { match: { 'parent.region_a': { analyzer: 'peliasAdmin', boost: 3, query: 'NY' } } }, { match: { 'parent.county': { analyzer: 'peliasAdmin', boost: 2, query: 'new york' } } }, { match: { 'parent.localadmin': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.locality': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.neighbourhood': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } } ]
//t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('valid query with partial address', function(t) {
var partial_address = 'soho grand, new york';
var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: parser.get_parsed_address(partial_address),
});
@ -158,8 +162,7 @@ module.exports.tests.query = function(test, common) {
test('valid query with regions in address', function(t) {
var partial_address = '1 water st manhattan ny';
var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: parser.get_parsed_address(partial_address),
});

12
test/unit/sanitiser/_layers.js

@ -43,7 +43,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var admin_layers = [ 'continent', 'macrocountry', 'country', 'dependency',
'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood',
'microhood', 'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin' ];
'microhood', 'disputed' ];
t.deepEqual(clean.layers, admin_layers, 'coarse layers set');
t.end();
@ -65,7 +65,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean);
var expected_layers = ['venue', 'country', 'admin0', 'region', 'admin1'];
var expected_layers = ['venue', 'country', 'region'];
t.deepEqual(clean.layers, expected_layers, 'venue + regular layers');
t.end();
});
@ -78,7 +78,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var expected_layers = [ 'continent', 'macrocountry', 'country', 'dependency',
'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood',
'microhood', 'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin' ];
'microhood', 'disputed' ];
t.deepEqual(clean.layers, expected_layers, 'coarse + regular layers set');
t.end();
@ -90,7 +90,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean);
var expected_layers = ['address', 'country', 'admin0', 'locality' ];
var expected_layers = ['address', 'country', 'locality' ];
t.deepEqual(clean.layers, expected_layers, 'address + regular layers set');
t.end();
});
@ -101,7 +101,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean);
var expected_layers = ['venue', 'country', 'admin0'];
var expected_layers = ['venue', 'country'];
t.deepEqual(clean.layers, expected_layers, 'venue layers found (no duplicates)');
t.end();
});
@ -115,7 +115,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var coarse_layers = [ 'continent', 'macrocountry',
'country', 'dependency', 'region', 'locality', 'localadmin',
'county', 'macrohood', 'neighbourhood', 'microhood',
'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin'];
'disputed' ];
var venue_layers = [ 'venue' ];
var expected_layers = venue_layers.concat(coarse_layers);

2
test/unit/sanitiser/search.js

@ -72,7 +72,7 @@ module.exports.tests.sanitise_valid_text = function(test, common) {
};
module.exports.tests.sanitize_text_with_delim = function(test, common) {
var texts = [ 'a,bcd', '123 main st, admin1', ',,,', ' ' ];
var texts = [ 'a,bcd', '123 main st, region', ',,,', ' ' ];
test('valid texts with a comma', function(t) {
texts.forEach( function( text ){

4
test/unit/service/mget.js

@ -20,14 +20,14 @@ module.exports.tests.functional_success = function(test, common) {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1'
parent: { country: 'country1', region: 'state1', county: 'city1' }
},
{
_id: 'myid2', _type: 'mytype2',
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2'
parent: { country: 'country2', region: 'state2', county: 'city2' }
}
];

4
test/unit/service/search.js

@ -23,7 +23,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1'
parent: { country: 'country1', region: 'state1', county: 'city1' }
},
{
_id: 'myid2', _type: 'mytype2',
@ -31,7 +31,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2'
parent: { country: 'country2', region: 'state2', county: 'city2' }
}
];

Loading…
Cancel
Save