diff --git a/helper/adminFields.js b/helper/adminFields.js deleted file mode 100644 index 31648bc4..00000000 --- a/helper/adminFields.js +++ /dev/null @@ -1,45 +0,0 @@ - -var _ = require('lodash'), - peliasSchema = require('pelias-schema'), - peliasLogger = require( 'pelias-logger' ).get( 'api' ); - -var ADMIN_FIELDS = [ - 'admin0', - 'admin1', - 'admin1_abbr', - 'admin2', - 'local_admin', - 'locality', - 'neighborhood', - 'address.zip' -]; - -/** - * Get all admin fields that were expected and also found in schema - * - * @param {Object} [schema] optional: for testing only - * @param {Array} [expectedFields] optional: for testing only - * @param {Object} [logger] optional: for testing only - * @returns {Array.} - */ -function getAvailableAdminFields(schema, expectedFields, logger) { - - schema = schema || peliasSchema; - expectedFields = expectedFields || ADMIN_FIELDS; - logger = logger || peliasLogger; - - var actualFields = Object.keys(schema.mappings._default_.properties); - - // check if expected fields are actually in current schema - var available = expectedFields.filter(function (field) { - return _.includes( actualFields, field ); - }); - - if (available.length === 0) { - logger.error('helper/adminFields: no expected admin fields found in schema'); - } - - return available; -} - -module.exports = getAvailableAdminFields; diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 8ed808f5..28fa6272 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -11,16 +11,25 @@ var DETAILS_PROPS = [ 'housenumber', 'street', 'postalcode', - 'country_a', + 'confidence', + 'distance', 'country', + 'country_id', + 'country_a', 'region', + 'region_id', 'region_a', 'county', + 'county_id', + 'county_a', 'localadmin', + 'localadmin_id', + 'localadmin_a', 'locality', + 'locality_id', + 'locality_a', 'neighbourhood', - 'confidence', - 'distance' + 'neighbourhood_id' ]; @@ -93,7 +102,7 @@ function addDetails(src, dst) { * @param {object} dst */ function addLabel(src, dst) { - dst.label = labelGenerator(src); + dst.label = labelGenerator(dst); } /** @@ -126,8 +135,23 @@ function computeBBox(geojson) { */ function copyProperties( source, props, dst ) { props.forEach( function ( prop ) { + if ( source.hasOwnProperty( prop ) ) { - dst[prop] = source[prop]; + + // array value, take first item in array (at this time only used for admin values) + if (source[prop] instanceof Array) { + if (source[prop].length === 0) { + return; + } + if (source[prop][0]) { + dst[prop] = source[prop][0]; + } + } + + // simple value + else { + dst[prop] = source[prop]; + } } }); } diff --git a/helper/labelGenerator.js b/helper/labelGenerator.js index e772ceb9..7e9c1827 100644 --- a/helper/labelGenerator.js +++ b/helper/labelGenerator.js @@ -1,4 +1,3 @@ - var _ = require('lodash'), schemas = require('./labelSchema'); @@ -11,7 +10,6 @@ module.exports = function( record ){ var valueFunction = schema[key]; labelParts = valueFunction(record, labelParts); - } // NOTE: while it may seem odd to call `uniq` on the list of label parts, @@ -54,6 +52,6 @@ function getInitialLabel(record) { return []; } - return [record.name.default]; + return [record.name]; } diff --git a/helper/type_mapping.js b/helper/type_mapping.js index ced5f1f3..39abb835 100644 --- a/helper/type_mapping.js +++ b/helper/type_mapping.js @@ -17,7 +17,7 @@ function addStandardTargetsToAliases(standard, aliases) { */ // a list of all sources -var SOURCES = ['openstreetmap', 'openaddresses', 'geonames', 'quattroshapes', 'whosonfirst']; +var SOURCES = ['openstreetmap', 'openaddresses', 'geonames', 'whosonfirst']; /* * A list of alternate names for sources, mostly used to save typing @@ -26,7 +26,6 @@ var SOURCE_ALIASES = { 'osm': ['openstreetmap'], 'oa': ['openaddresses'], 'gn': ['geonames'], - 'qs': ['quattroshapes'], 'wof': ['whosonfirst'] }; @@ -49,7 +48,6 @@ var LAYERS_BY_SOURCE = { openstreetmap: [ 'address', 'venue' ], openaddresses: [ 'address' ], geonames: [ 'country', 'region', 'county', 'locality', 'venue' ], - quattroshapes: ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'], whosonfirst: [ 'continent', 'macrocountry', 'country', 'dependency', 'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood', 'microhood', 'disputed'] }; @@ -60,9 +58,7 @@ var LAYERS_BY_SOURCE = { * may have layers that mean the same thing but have a different name */ var LAYER_ALIASES = { - 'coarse': LAYERS_BY_SOURCE.whosonfirst.concat(LAYERS_BY_SOURCE.quattroshapes), - 'country': ['country', 'admin0'], // Include both QS and WOF layers for various types of places - 'region': ['region', 'admin1'] // Alias layers that include themselves look weird, but do work + 'coarse': LAYERS_BY_SOURCE.whosonfirst }; // create a list of all layers by combining each entry from LAYERS_BY_SOURCE diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index 0eae0f8d..3cd9d1f3 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -84,7 +84,7 @@ function computeConfidenceScore(req, mean, stdev, hit) { /* * Check for clearly mismatching properties in a result - * zip code and state (admin1) are currently checked if present + * zip code and state (region) are currently checked if present * * @param {object|undefined} text * @param {object} hit @@ -95,8 +95,8 @@ function checkForDealBreakers(req, hit) { return false; } - if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.admin1_abbr) { - logger.debug('[confidence][deal-breaker]: state !== admin1_abbr'); + if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a) { + logger.debug('[confidence][deal-breaker]: state !== region_a'); return true; } @@ -210,8 +210,8 @@ function propMatch(textProp, hitProp, expectEnriched) { * @param {string|number} [hit.address.number] * @param {string} [hit.address.street] * @param {string|number} [hit.address.zip] - * @param {string} [hit.admin1_abbr] - * @param {string} [hit.alpha3] + * @param {string} [hit.parent.region_a] + * @param {string} [hit.parent.country_a] * @returns {number} */ function checkAddress(text, hit) { @@ -222,8 +222,8 @@ function checkAddress(text, hit) { res += propMatch(text.number, (hit.address ? hit.address.number : null), false); res += propMatch(text.street, (hit.address ? hit.address.street : null), false); res += propMatch(text.postalcode, (hit.address ? hit.address.zip: null), true); - res += propMatch(text.state, hit.admin1_abbr, true); - res += propMatch(text.country, hit.alpha3, true); + res += propMatch(text.state, hit.parent.region_a, true); + res += propMatch(text.country, hit.parent.country_a, true); res /= checkCount; } diff --git a/middleware/dedupe.js b/middleware/dedupe.js index 87bf20db..9e0e5c6a 100644 --- a/middleware/dedupe.js +++ b/middleware/dedupe.js @@ -39,8 +39,13 @@ function dedupeResults(req, res, next) { */ function isDifferent(item1, item2) { try { - propMatch(item1, item2, 'admin1_abbr'); - propMatch(item1, item2, 'alpha3'); + if (item1.hasOwnProperty('parent') && item2.hasOwnProperty('parent')) { + propMatch(item1.parent, item2.parent, 'region_a'); + propMatch(item1.parent, item2.parent, 'country'); + } + else if (item1.parent !== item2.parent) { + throw new Error('different'); + } if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) { propMatch(item1.name, item2.name, 'default'); @@ -77,7 +82,17 @@ function isDifferent(item1, item2) { * @throws {Error} */ function propMatch(item1, item2, prop) { - if (normalizeString(item1[prop]) !== normalizeString(item2[prop])) { + var prop1 = item1[prop]; + var prop2 = item2[prop]; + + // in the case the property is an array (currently only in parent schema) + // simply take the 1st item. this will change in the near future to support multiple hierarchies + if (_.isArray(prop1) && _.isArray(prop2)) { + prop1 = prop1[0]; + prop2= prop2[0]; + } + + if (normalizeString(prop1) !== normalizeString(prop2)) { throw new Error('different'); } } diff --git a/middleware/localNamingConventions.js b/middleware/localNamingConventions.js index b7c5b8c9..084cfc26 100644 --- a/middleware/localNamingConventions.js +++ b/middleware/localNamingConventions.js @@ -13,7 +13,7 @@ function applyLocalNamingConventions(req, res, next) { // loop through data items and flip relevant number/street res.data.filter(function(place){ // only relevant for German addresses - if( 'DEU' !== place.alpha3 ){ return false; } + if( 'DEU' !== place.parent.country_a ){ return false; } if( !place.hasOwnProperty('address') ){ return false; } if( !place.address.hasOwnProperty('number') ){ return false; } if( !place.address.hasOwnProperty('street') ){ return false; } diff --git a/middleware/renamePlacenames.js b/middleware/renamePlacenames.js index 6fcba91a..8f171e24 100644 --- a/middleware/renamePlacenames.js +++ b/middleware/renamePlacenames.js @@ -1,4 +1,4 @@ -var extend = require('extend'); +var _ = require('lodash'); /** - P is a preferred English name @@ -11,56 +11,67 @@ var extend = require('extend'); - A is an abbreviation or code for the place (e.g. "NYC" for New York) */ -// config mapping of old names to new ones -var NAME_MAP = { + +var ADDRESS_PROPS = { 'number': 'housenumber', 'zip': 'postalcode', - 'alpha3': 'country_a', - 'admin0': 'country', - 'admin1': 'region', - 'admin1_abbr': 'region_a', - 'admin2': 'county', - 'local_admin': 'localadmin', - 'neighborhood': 'neighbourhood' + 'street': 'street' }; -function setup() { +var PARENT_PROPS = [ + 'country', + 'country_id', + 'country_a', + 'region', + 'region_id', + 'region_a', + 'county', + 'county_id', + 'county_a', + 'localadmin', + 'localadmin_id', + 'localadmin_a', + 'locality', + 'locality_id', + 'locality_a', + 'neighbourhood', + 'neighbourhood_id' +]; + +function setup() { return renamePlacenames; } function renamePlacenames(req, res, next) { - // do nothing if no result data set if (!res || !res.data) { return next(); } - // loop through data items and remap placenames - res.data = res.data.map(renameProperties); + res.data = res.data.map(renameOneRecord); next(); } -function renameProperties(place) { - var newPlace = {}; - Object.keys(place).forEach(function (property) { - if (property === 'address') { - extend(newPlace, renameProperties(place[property])); - } - else { - renameProperty(place, newPlace, property); - } - }); - return newPlace; -} +/* + * Rename the fields in one record + */ +function renameOneRecord(place) { + if (place.address) { + Object.keys(ADDRESS_PROPS).forEach(function (prop) { + place[ADDRESS_PROPS[prop]] = place.address[prop]; + }); + } -function renameProperty(oldObj, newObj, property) { - if (!oldObj.hasOwnProperty(property)) { - return; + // merge the parent block into the top level object to flatten the structure + if (place.parent) { + PARENT_PROPS.forEach(function (prop) { + place[prop] = place.parent[prop]; + }); } - newObj[(NAME_MAP[property] || property)] = oldObj[property]; + return place; } module.exports = setup; diff --git a/package.json b/package.json index 180576f6..8e576b42 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,7 @@ "pelias-config": "^1.0.1", "pelias-esclient": "1.0.0", "pelias-logger": "^0.0.8", - "pelias-query": "^5.1.0", - "pelias-schema": "3.0.0", + "pelias-query": "^6.0.0", "pelias-suggester-pipeline": "2.0.4", "stats-lite": "1.0.3", "through2": "2.0.1" diff --git a/public/attribution.md b/public/attribution.md index c7697d2e..12799e0c 100644 --- a/public/attribution.md +++ b/public/attribution.md @@ -1,6 +1,7 @@ ## Attribution -* Geocoding by [Pelias](https://mapzen.com/pelias) from [Mapzen](https://mapzen.com) -* Data from +Geocoding by [Mapzen Search](https://mapzen.com/projects/search) from [Mapzen](https://mapzen.com). Powered by [Pelias](https://github.com/pelias/pelias) geocoding engine. + +Data from: * [OpenStreetMap](http://www.openstreetmap.org/copyright) © OpenStreetMap contributors under [ODbL](http://opendatacommons.org/licenses/odbl/) * [Quattroshapes](https://github.com/foursquare/quattroshapes/blob/master/LICENSE.md) licensed under [CC-BY-2.0](https://creativecommons.org/licenses/by/2.0/) * [GeoNames](http://www.geonames.org/) licensed under CC-BY-3.0](https://creativecommons.org/licenses/by/2.0/) diff --git a/query/autocomplete.js b/query/autocomplete.js index bf5f76aa..4bc98c7c 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -27,14 +27,14 @@ query.score( peliasQuery.view.address('street') ); query.score( peliasQuery.view.address('postcode') ); // admin components -query.score( peliasQuery.view.admin('alpha3') ); -query.score( peliasQuery.view.admin('admin0') ); -query.score( peliasQuery.view.admin('admin1') ); -query.score( peliasQuery.view.admin('admin1_abbr') ); -query.score( peliasQuery.view.admin('admin2') ); -query.score( peliasQuery.view.admin('local_admin') ); +query.score( peliasQuery.view.admin('country') ); +query.score( peliasQuery.view.admin('country_a') ); +query.score( peliasQuery.view.admin('region') ); +query.score( peliasQuery.view.admin('region_a') ); +query.score( peliasQuery.view.admin('county') ); +query.score( peliasQuery.view.admin('localadmin') ); query.score( peliasQuery.view.admin('locality') ); -query.score( peliasQuery.view.admin('neighborhood') ); +query.score( peliasQuery.view.admin('neighbourhood') ); // scoring boost query.score( views.focus_selected_layers( views.ngrams_strict ) ); diff --git a/query/autocomplete_defaults.js b/query/autocomplete_defaults.js index df1b206f..7bb430cc 100644 --- a/query/autocomplete_defaults.js +++ b/query/autocomplete_defaults.js @@ -50,37 +50,37 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'address:postcode:field': 'address.zip', 'address:postcode:boost': 2000, - 'admin:alpha3:analyzer': 'standard', - 'admin:alpha3:field': 'alpha3', - 'admin:alpha3:boost': 1000, + 'admin:country_a:analyzer': 'standard', + 'admin:country_a:field': 'parent.country_a', + 'admin:country_a:boost': 1000, - 'admin:admin0:analyzer': 'peliasAdmin', - 'admin:admin0:field': 'admin0', - 'admin:admin0:boost': 800, + 'admin:country:analyzer': 'peliasAdmin', + 'admin:country:field': 'parent.country', + 'admin:country:boost': 800, - 'admin:admin1:analyzer': 'peliasAdmin', - 'admin:admin1:field': 'admin1', - 'admin:admin1:boost': 600, + 'admin:region:analyzer': 'peliasAdmin', + 'admin:region:field': 'parent.region', + 'admin:region:boost': 600, - 'admin:admin1_abbr:analyzer': 'peliasAdmin', - 'admin:admin1_abbr:field': 'admin1_abbr', - 'admin:admin1_abbr:boost': 600, + 'admin:region_a:analyzer': 'peliasAdmin', + 'admin:region_a:field': 'parent.region_a', + 'admin:region_a:boost': 600, - 'admin:admin2:analyzer': 'peliasAdmin', - 'admin:admin2:field': 'admin2', - 'admin:admin2:boost': 400, + 'admin:county:analyzer': 'peliasAdmin', + 'admin:county:field': 'parent.county', + 'admin:county:boost': 400, - 'admin:local_admin:analyzer': 'peliasAdmin', - 'admin:local_admin:field': 'local_admin', - 'admin:local_admin:boost': 200, + 'admin:localadmin:analyzer': 'peliasAdmin', + 'admin:localadmin:field': 'parent.localadmin', + 'admin:localadmin:boost': 200, 'admin:locality:analyzer': 'peliasAdmin', - 'admin:locality:field': 'locality', + 'admin:locality:field': 'parent.locality', 'admin:locality:boost': 200, - 'admin:neighborhood:analyzer': 'peliasAdmin', - 'admin:neighborhood:field': 'neighborhood', - 'admin:neighborhood:boost': 200, + 'admin:neighbourhood:analyzer': 'peliasAdmin', + 'admin:neighbourhood:field': 'parent.neighbourhood', + 'admin:neighbourhood:boost': 200, 'popularity:field': 'popularity', 'popularity:modifier': 'log1p', diff --git a/query/reverse_defaults.js b/query/reverse_defaults.js index 01e74773..c32b1c3d 100644 --- a/query/reverse_defaults.js +++ b/query/reverse_defaults.js @@ -50,37 +50,37 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'address:postcode:field': 'address.zip', 'address:postcode:boost': 3, - 'admin:alpha3:analyzer': 'standard', - 'admin:alpha3:field': 'alpha3', - 'admin:alpha3:boost': 5, + 'admin:country_a:analyzer': 'standard', + 'admin:country_a:field': 'parent.country_a', + 'admin:country_a:boost': 5, - 'admin:admin0:analyzer': 'peliasAdmin', - 'admin:admin0:field': 'admin0', - 'admin:admin0:boost': 4, + 'admin:country:analyzer': 'peliasAdmin', + 'admin:country:field': 'parent.country', + 'admin:country:boost': 4, - 'admin:admin1:analyzer': 'peliasAdmin', - 'admin:admin1:field': 'admin1', - 'admin:admin1:boost': 3, + 'admin:region:analyzer': 'peliasAdmin', + 'admin:region:field': 'parent.region', + 'admin:region:boost': 3, - 'admin:admin1_abbr:analyzer': 'peliasAdmin', - 'admin:admin1_abbr:field': 'admin1_abbr', - 'admin:admin1_abbr:boost': 3, + 'admin:region_a:analyzer': 'peliasAdmin', + 'admin:region_a:field': 'parent.region_a', + 'admin:region_a:boost': 3, - 'admin:admin2:analyzer': 'peliasAdmin', - 'admin:admin2:field': 'admin2', - 'admin:admin2:boost': 2, + 'admin:county:analyzer': 'peliasAdmin', + 'admin:county:field': 'parent.county', + 'admin:county:boost': 2, - 'admin:local_admin:analyzer': 'peliasAdmin', - 'admin:local_admin:field': 'local_admin', - 'admin:local_admin:boost': 1, + 'admin:localadmin:analyzer': 'peliasAdmin', + 'admin:localadmin:field': 'parent.localadmin', + 'admin:localadmin:boost': 1, 'admin:locality:analyzer': 'peliasAdmin', - 'admin:locality:field': 'locality', + 'admin:locality:field': 'parent.locality', 'admin:locality:boost': 1, - 'admin:neighborhood:analyzer': 'peliasAdmin', - 'admin:neighborhood:field': 'neighborhood', - 'admin:neighborhood:boost': 1, + 'admin:neighbourhood:analyzer': 'peliasAdmin', + 'admin:neighbourhood:field': 'parent.neighbourhood', + 'admin:neighbourhood:boost': 1, 'popularity:field': 'popularity', 'popularity:modifier': 'log1p', diff --git a/query/search.js b/query/search.js index 804cb88b..1db1a10a 100644 --- a/query/search.js +++ b/query/search.js @@ -25,14 +25,14 @@ query.score( peliasQuery.view.address('street') ); query.score( peliasQuery.view.address('postcode') ); // admin components -query.score( peliasQuery.view.admin('alpha3') ); -query.score( peliasQuery.view.admin('admin0') ); -query.score( peliasQuery.view.admin('admin1') ); -query.score( peliasQuery.view.admin('admin1_abbr') ); -query.score( peliasQuery.view.admin('admin2') ); -query.score( peliasQuery.view.admin('local_admin') ); +query.score( peliasQuery.view.admin('country') ); +query.score( peliasQuery.view.admin('country_a') ); +query.score( peliasQuery.view.admin('region') ); +query.score( peliasQuery.view.admin('region_a') ); +query.score( peliasQuery.view.admin('county') ); +query.score( peliasQuery.view.admin('localadmin') ); query.score( peliasQuery.view.admin('locality') ); -query.score( peliasQuery.view.admin('neighborhood') ); +query.score( peliasQuery.view.admin('neighbourhood') ); // non-scoring hard filters query.filter( peliasQuery.view.boundary_circle ); diff --git a/query/search_defaults.js b/query/search_defaults.js index 28cf6e7a..e9a918cd 100644 --- a/query/search_defaults.js +++ b/query/search_defaults.js @@ -50,37 +50,37 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'address:postcode:field': 'address.zip', 'address:postcode:boost': 20, - 'admin:alpha3:analyzer': 'standard', - 'admin:alpha3:field': 'alpha3', - 'admin:alpha3:boost': 5, + 'admin:country_a:analyzer': 'standard', + 'admin:country_a:field': 'parent.country_a', + 'admin:country_a:boost': 5, - 'admin:admin0:analyzer': 'peliasAdmin', - 'admin:admin0:field': 'admin0', - 'admin:admin0:boost': 4, + 'admin:country:analyzer': 'peliasAdmin', + 'admin:country:field': 'parent.country', + 'admin:country:boost': 4, - 'admin:admin1:analyzer': 'peliasAdmin', - 'admin:admin1:field': 'admin1', - 'admin:admin1:boost': 3, + 'admin:region:analyzer': 'peliasAdmin', + 'admin:region:field': 'parent.region', + 'admin:region:boost': 3, - 'admin:admin1_abbr:analyzer': 'peliasAdmin', - 'admin:admin1_abbr:field': 'admin1_abbr', - 'admin:admin1_abbr:boost': 3, + 'admin:region_a:analyzer': 'peliasAdmin', + 'admin:region_a:field': 'parent.region_a', + 'admin:region_a:boost': 3, - 'admin:admin2:analyzer': 'peliasAdmin', - 'admin:admin2:field': 'admin2', - 'admin:admin2:boost': 2, + 'admin:county:analyzer': 'peliasAdmin', + 'admin:county:field': 'parent.county', + 'admin:county:boost': 2, - 'admin:local_admin:analyzer': 'peliasAdmin', - 'admin:local_admin:field': 'local_admin', - 'admin:local_admin:boost': 1, + 'admin:localadmin:analyzer': 'peliasAdmin', + 'admin:localadmin:field': 'parent.localadmin', + 'admin:localadmin:boost': 1, 'admin:locality:analyzer': 'peliasAdmin', - 'admin:locality:field': 'locality', + 'admin:locality:field': 'parent.locality', 'admin:locality:boost': 1, - 'admin:neighborhood:analyzer': 'peliasAdmin', - 'admin:neighborhood:field': 'neighborhood', - 'admin:neighborhood:boost': 1, + 'admin:neighbourhood:analyzer': 'peliasAdmin', + 'admin:neighbourhood:field': 'parent.neighbourhood', + 'admin:neighbourhood:boost': 1, 'popularity:field': 'popularity', 'popularity:modifier': 'log1p', diff --git a/query/text_parser.js b/query/text_parser.js index 408d00f9..38fca48e 100644 --- a/query/text_parser.js +++ b/query/text_parser.js @@ -1,6 +1,20 @@ var logger = require('pelias-logger').get('api'); -var adminFields = require('../helper/adminFields')(); + +/* +This list should only contain admin fields we are comfortable matching in the case +when we can't identify parts of an address. This shouldn't contain fields like country_a +or postalcode because we should only try to match those when we're sure that's what they are. + */ +var adminFields = [ + 'country', + 'region', + 'region_a', + 'county', + 'localadmin', + 'locality', + 'neighbourhood' +]; /** @todo: refactor me @@ -48,17 +62,17 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){ // city if( parsed_text.hasOwnProperty('city') ){ - vs.var( 'input:admin2', parsed_text.city ); + vs.var( 'input:county', parsed_text.city ); } // state if( parsed_text.hasOwnProperty('state') ){ - vs.var( 'input:admin1_abbr', parsed_text.state ); + vs.var( 'input:region_a', parsed_text.state ); } // country if( parsed_text.hasOwnProperty('country') ){ - vs.var( 'input:alpha3', parsed_text.country ); + vs.var( 'input:country_a', parsed_text.country ); } // ==== deal with the 'leftover' components ==== @@ -76,11 +90,10 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){ // if we have 'leftovers' then assign them to any fields which // currently don't have a value assigned. if( leftoversString.length ){ - var unmatchedAdminFields = adminFields.slice(); - + // cycle through fields and set fields which // are still currently unset - unmatchedAdminFields.forEach( function( key ){ + adminFields.forEach( function( key ){ if( !vs.isset( 'input:' + key ) ){ vs.var( 'input:' + key, leftoversString ); } diff --git a/test/ciao/reverse/layers_alias_coarse.coffee b/test/ciao/reverse/layers_alias_coarse.coffee index 6b911083..f16f5a17 100644 --- a/test/ciao/reverse/layers_alias_coarse.coffee +++ b/test/ciao/reverse/layers_alias_coarse.coffee @@ -41,10 +41,5 @@ json.geocoding.query.layers.should.eql [ "continent", "macrohood", "neighbourhood", "microhood", - "disputed", - "admin0", - "admin1", - "admin2", - "neighborhood", - "local_admin" + "disputed" ] diff --git a/test/ciao/reverse/layers_invalid.coffee b/test/ciao/reverse/layers_invalid.coffee index a7105815..9d89e05a 100644 --- a/test/ciao/reverse/layers_invalid.coffee +++ b/test/ciao/reverse/layers_invalid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,country,region,address,venue,county,locality,admin0,admin1,admin2,neighborhood,local_admin,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/reverse/layers_mix_invalid_valid.coffee b/test/ciao/reverse/layers_mix_invalid_valid.coffee index f8e07adf..3e6a57fe 100644 --- a/test/ciao/reverse/layers_mix_invalid_valid.coffee +++ b/test/ciao/reverse/layers_mix_invalid_valid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,country,region,address,venue,county,locality,admin0,admin1,admin2,neighborhood,local_admin,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/reverse/layers_multiple.coffee b/test/ciao/reverse/layers_multiple.coffee index d85c07a2..75b466d2 100644 --- a/test/ciao/reverse/layers_multiple.coffee +++ b/test/ciao/reverse/layers_multiple.coffee @@ -30,4 +30,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -json.geocoding.query.layers.should.eql ["country","admin0","region","admin1"] +json.geocoding.query.layers.should.eql ["country","region"] diff --git a/test/ciao/reverse/layers_single.coffee b/test/ciao/reverse/layers_single.coffee index ab1f8e08..8f5220eb 100644 --- a/test/ciao/reverse/layers_single.coffee +++ b/test/ciao/reverse/layers_single.coffee @@ -30,4 +30,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -json.geocoding.query.layers.should.eql ["country","admin0"] +json.geocoding.query.layers.should.eql ["country"] diff --git a/test/ciao/reverse/sources_invalid.coffee b/test/ciao/reverse/sources_invalid.coffee index f0b54803..62a6c4c2 100644 --- a/test/ciao/reverse/sources_invalid.coffee +++ b/test/ciao/reverse/sources_invalid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: osm,oa,gn,qs,wof,openstreetmap,openaddresses,geonames,quattroshapes,whosonfirst' ] +json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/reverse/sources_layers_invalid_combo.coffee b/test/ciao/reverse/sources_layers_invalid_combo.coffee index 984830a7..baf157cc 100644 --- a/test/ciao/reverse/sources_layers_invalid_combo.coffee +++ b/test/ciao/reverse/sources_layers_invalid_combo.coffee @@ -1,6 +1,6 @@ #> sources and layers specified (invalid combo) -path: '/v1/reverse?point.lat=1&point.lon=2&sources=quattroshapes&layers=address' +path: '/v1/reverse?point.lat=1&point.lon=2&sources=whosonfirst&layers=address' #? 200 ok response.statusCode.should.be.equal 400 @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results: the quattroshapes source has nothing in the address layer' ] +json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results: the whosonfirst source has nothing in the address layer' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query.layers.should.eql ["address"] -json.geocoding.query.sources.should.eql ["quattroshapes"] +json.geocoding.query.sources.should.eql ["whosonfirst"] diff --git a/test/ciao/search/layers_alias_coarse.coffee b/test/ciao/search/layers_alias_coarse.coffee index c2527df0..9dda2a48 100644 --- a/test/ciao/search/layers_alias_coarse.coffee +++ b/test/ciao/search/layers_alias_coarse.coffee @@ -42,10 +42,5 @@ json.geocoding.query.layers.should.eql [ "continent", "macrohood", "neighbourhood", "microhood", - "disputed", - "admin0", - "admin1", - "admin2", - "neighborhood", - "local_admin" + "disputed" ] diff --git a/test/ciao/search/layers_invalid.coffee b/test/ciao/search/layers_invalid.coffee index 40de3f85..5d07f99c 100644 --- a/test/ciao/search/layers_invalid.coffee +++ b/test/ciao/search/layers_invalid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,country,region,address,venue,county,locality,admin0,admin1,admin2,neighborhood,local_admin,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/search/layers_mix_invalid_valid.coffee b/test/ciao/search/layers_mix_invalid_valid.coffee index 6f1ccec6..0a13c70b 100644 --- a/test/ciao/search/layers_mix_invalid_valid.coffee +++ b/test/ciao/search/layers_mix_invalid_valid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,country,region,address,venue,county,locality,admin0,admin1,admin2,neighborhood,local_admin,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,macrocountry,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/search/layers_multiple.coffee b/test/ciao/search/layers_multiple.coffee index c735a206..2555573e 100644 --- a/test/ciao/search/layers_multiple.coffee +++ b/test/ciao/search/layers_multiple.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -json.geocoding.query.layers.should.eql ["country","admin0","region","admin1"] +json.geocoding.query.layers.should.eql ["country","region"] diff --git a/test/ciao/search/layers_single.coffee b/test/ciao/search/layers_single.coffee index ad104fab..e1931c04 100644 --- a/test/ciao/search/layers_single.coffee +++ b/test/ciao/search/layers_single.coffee @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -json.geocoding.query.layers.should.eql ["country","admin0"] +json.geocoding.query.layers.should.eql ["country"] diff --git a/test/ciao/search/sources_invalid.coffee b/test/ciao/search/sources_invalid.coffee index 8b6b9d27..1620d7ba 100644 --- a/test/ciao/search/sources_invalid.coffee +++ b/test/ciao/search/sources_invalid.coffee @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: osm,oa,gn,qs,wof,openstreetmap,openaddresses,geonames,quattroshapes,whosonfirst' ] +json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst' ] #? expected warnings should.not.exist json.geocoding.warnings diff --git a/test/ciao/search/sources_layers_invalid_combo.coffee b/test/ciao/search/sources_layers_invalid_combo.coffee index d1e0fc07..821bf243 100644 --- a/test/ciao/search/sources_layers_invalid_combo.coffee +++ b/test/ciao/search/sources_layers_invalid_combo.coffee @@ -1,6 +1,6 @@ #> sources and layers specified (invalid combo) -path: '/v1/search?text=a&sources=quattroshapes&layers=address' +path: '/v1/search?text=a&sources=whosonfirst&layers=address' #? 200 ok response.statusCode.should.be.equal 400 @@ -24,7 +24,7 @@ json.features.should.be.instanceof Array #? expected errors should.exist json.geocoding.errors -json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results: the quattroshapes source has nothing in the address layer' ] +json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results: the whosonfirst source has nothing in the address layer' ] #? expected warnings should.not.exist json.geocoding.warnings @@ -33,5 +33,5 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query.layers.should.eql ["address"] -json.geocoding.query.sources.should.eql ["quattroshapes"] +json.geocoding.query.sources.should.eql ["whosonfirst"] should.not.exist json.geocoding.query['type'] diff --git a/test/unit/controller/search.js b/test/unit/controller/search.js index 2b412013..3d46dde0 100644 --- a/test/unit/controller/search.js +++ b/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 diff --git a/test/unit/fixture/autocomplete_linguistic_with_admin.js b/test/unit/fixture/autocomplete_linguistic_with_admin.js index 2174fcbf..2c27f670 100644 --- a/test/unit/fixture/autocomplete_linguistic_with_admin.js +++ b/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' diff --git a/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js b/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js index 3341141a..ce929152 100644 --- a/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js +++ b/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 } ]; \ No newline at end of file diff --git a/test/unit/fixture/dedupe_elasticsearch_results.js b/test/unit/fixture/dedupe_elasticsearch_results.js index 6ed761c4..84b279d3 100644 --- a/test/unit/fixture/dedupe_elasticsearch_results.js +++ b/test/unit/fixture/dedupe_elasticsearch_results.js @@ -5,22 +5,24 @@ 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' ], '_id': '357321757', - '_type': 'osmnode', + '_type': 'venue', '_score': 1.2367082, 'confidence': 0.879 }, @@ -30,22 +32,24 @@ 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' ], '_id': '357321757', - '_type': 'osmnode', + '_type': 'venue', '_score': 1.2367082, 'confidence': 0.879 }, @@ -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,22 +113,24 @@ 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' ], '_id': '357294404', - '_type': 'osmnode', + '_type': 'venue', '_score': 1.2367082, 'confidence': 0.879 }, @@ -130,22 +140,24 @@ 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' ], '_id': '357283977', - '_type': 'osmnode', + '_type': 'venue', '_score': 1.1036991, 'confidence': 0.664 }, @@ -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,21 +194,23 @@ 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' ], '_id': '358058986', - '_type': 'osmnode', + '_type': 'venue', '_score': 1.0492544, 'confidence': 0.658 }, @@ -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,22 +272,24 @@ 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' ], '_id': '356646971', - '_type': 'osmway', + '_type': 'venue', '_score': 0.9724125, 'confidence': 0.649 } -]; \ No newline at end of file +]; diff --git a/test/unit/fixture/reverse_with_boundary_country.js b/test/unit/fixture/reverse_with_boundary_country.js index 8d739eaa..789cadaf 100644 --- a/test/unit/fixture/reverse_with_boundary_country.js +++ b/test/unit/fixture/reverse_with_boundary_country.js @@ -8,7 +8,7 @@ module.exports = { 'must': [ { 'match': { - 'alpha3': { + 'parent.country_a': { 'analyzer': 'standard', 'query': 'ABC' } diff --git a/test/unit/fixture/search_boundary_country.js b/test/unit/fixture/search_boundary_country.js index 3e6f83bc..5dde3344 100644 --- a/test/unit/fixture/search_boundary_country.js +++ b/test/unit/fixture/search_boundary_country.js @@ -7,7 +7,7 @@ module.exports = { 'must': [ { 'match': { - 'alpha3': { + 'parent.country_a': { 'analyzer': 'standard', 'query': 'ABC' } diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index 316903e7..859cfda4 100644 --- a/test/unit/fixture/search_full_address.js +++ b/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'] } } }] diff --git a/test/unit/fixture/search_partial_address.js b/test/unit/fixture/search_partial_address.js index 745598da..d857e31b 100644 --- a/test/unit/fixture/search_partial_address.js +++ b/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'] } } }] diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index 51bb57cc..25beb280 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/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'] } } }] diff --git a/test/unit/helper/adminFields.js b/test/unit/helper/adminFields.js deleted file mode 100644 index 8780b267..00000000 --- a/test/unit/helper/adminFields.js +++ /dev/null @@ -1,84 +0,0 @@ -var adminFields = require('../../../helper/adminFields'); - -module.exports.tests = {}; - -module.exports.tests.interface = function(test, common) { - test('validate fields', function(t) { - t.assert(adminFields instanceof Function, 'adminFields is a function'); - t.assert(adminFields() instanceof Array, 'adminFields() returns an array'); - t.assert(adminFields().length > 0, 'adminFields array is not empty'); - t.end(); - }); -}; - -module.exports.tests.lookupExistance = function(test, common) { - test('all expected fields in schema', function(t) { - - var expectedFields = [ - 'one', - 'two', - 'three', - 'four' - ]; - var schema = { mappings: { _default_: { properties: {} } } }; - - // inject all expected fields into schema mock - expectedFields.forEach(function (field) { - schema.mappings._default_.properties[field] = {}; - }); - - var res = adminFields(schema, expectedFields); - - t.deepEquals(res, expectedFields, 'all expected fields are returned'); - t.end(); - }); - - test('some expected fields in schema', function(t) { - - var expectedFields = [ - 'one', - 'two', - 'three', - 'four' - ]; - var schema = { mappings: { _default_: { properties: {} } } }; - - // inject only some of the expected fields into schema mock - expectedFields.slice(0, 3).forEach(function (field) { - schema.mappings._default_.properties[field] = {}; - }); - - var res = adminFields(schema, expectedFields); - - t.deepEquals(res, expectedFields.slice(0, 3), 'only matching expected fields are returned'); - t.end(); - }); - - test('no expected fields in schema', function(t) { - - var schema = { mappings: { _default_: { properties: { foo: {} } } } }; - - var logErrorCalled = false; - var logger = { - error: function () { - logErrorCalled = true; - }}; - - var res = adminFields(schema, undefined, logger); - - t.deepEquals(res, [], 'no admin fields found'); - t.assert(logErrorCalled, 'log error called'); - t.end(); - }); -}; - -module.exports.all = function (tape, common) { - - function test(name, testFunction) { - return tape('adminFields: ' + name, testFunction); - } - - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; \ No newline at end of file diff --git a/test/unit/helper/labelGenerator_GBR.js b/test/unit/helper/labelGenerator_GBR.js index 38ab3f91..a121444c 100644 --- a/test/unit/helper/labelGenerator_GBR.js +++ b/test/unit/helper/labelGenerator_GBR.js @@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) { module.exports.tests.one_main_street_uk = function(test, common) { test('one main street uk', function(t) { var doc = { - 'name': { 'default': '1 Main St' }, + 'name': '1 Main St', 'housenumber': '1', 'street': 'Main St', 'postalcode': 'BT77 0BG', @@ -31,7 +31,7 @@ module.exports.tests.one_main_street_uk = function(test, common) { module.exports.tests.hackney_city_farm = function(test, common) { test('hackney city farm', function(t) { var doc = { - 'name': { 'default': 'Hackney City Farm' }, + 'name': 'Hackney City Farm', 'country_a': 'GBR', 'country': 'United Kingdom', 'region': 'Hackney', @@ -48,7 +48,7 @@ module.exports.tests.hackney_city_farm = function(test, common) { module.exports.tests.wales = function(test, common) { test('wales', function(t) { var doc = { - 'name': { 'default': 'Wales' }, + 'name': 'Wales', 'country_a': 'GBR', 'country': 'United Kingdom', 'region': 'Wales' diff --git a/test/unit/helper/labelGenerator_SGP.js b/test/unit/helper/labelGenerator_SGP.js index 92aca117..622f8915 100644 --- a/test/unit/helper/labelGenerator_SGP.js +++ b/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', diff --git a/test/unit/helper/labelGenerator_SWE.js b/test/unit/helper/labelGenerator_SWE.js index edefc93a..e3f8534d 100644 --- a/test/unit/helper/labelGenerator_SWE.js +++ b/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', diff --git a/test/unit/helper/labelGenerator_USA.js b/test/unit/helper/labelGenerator_USA.js index e4b412ba..7791aa24 100644 --- a/test/unit/helper/labelGenerator_USA.js +++ b/test/unit/helper/labelGenerator_USA.js @@ -12,7 +12,7 @@ module.exports.tests.interface = function(test, common) { module.exports.tests.localadmin = function(test, common) { test('localadmin should trump locality, neighbourhood, and county', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -30,7 +30,7 @@ module.exports.tests.localadmin = function(test, common) { module.exports.tests.locality = function(test, common) { test('locality should trump neighbourhood and county when localadmin not available', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -47,7 +47,7 @@ module.exports.tests.locality = function(test, common) { module.exports.tests.neighbourhood = function(test, common) { test('neighbourhood should trump county when neither localadmin nor locality', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -63,7 +63,7 @@ module.exports.tests.neighbourhood = function(test, common) { module.exports.tests.county = function(test, common) { test('county should be used when localadmin, locality, and neighbourhood are not available', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -78,7 +78,7 @@ module.exports.tests.county = function(test, common) { module.exports.tests.region = function(test, common) { test('region should be used when region_a is not available', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name' @@ -92,7 +92,7 @@ module.exports.tests.region = function(test, common) { module.exports.tests.region_geonames = function(test, common) { test('default name should not be prepended when source=geonames and layer=region', function(t) { var doc = { - 'name': { 'default': 'Region Name' }, + 'name': 'Region Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -109,7 +109,7 @@ module.exports.tests.region_geonames = function(test, common) { module.exports.tests.region_whosonfirst = function(test, common) { test('default name should not be prepended when source=whosonfirst and layer=region', function(t) { var doc = { - 'name': { 'default': 'Region Name' }, + 'name': 'Region Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -126,7 +126,7 @@ module.exports.tests.region_whosonfirst = function(test, common) { module.exports.tests.region_other_source = function(test, common) { test('default name should be prepended when layer=region and source is not whosonfirst or geonames', function(t) { var doc = { - 'name': { 'default': 'Default Name' }, + 'name': 'Default Name', 'country_a': 'USA', 'country': 'United States', 'region': 'Region Name', @@ -143,7 +143,7 @@ module.exports.tests.region_other_source = function(test, common) { module.exports.tests.san_francisco = function(test, common) { test('san francisco', function(t) { var doc = { - 'name': { 'default': 'San Francisco' }, + 'name': 'San Francisco', 'country_a': 'USA', 'country': 'United States', 'region': 'California', @@ -160,7 +160,7 @@ module.exports.tests.san_francisco = function(test, common) { module.exports.tests.nyc_office = function(test, common) { test('30 West 26th Street', function(t) { var doc = { - 'name': { 'default': '30 West 26th Street' }, + 'name': '30 West 26th Street', 'housenumber': '30', 'street': 'West 26th Street', 'postalcode': '10010', @@ -182,7 +182,7 @@ module.exports.tests.nyc_office = function(test, common) { module.exports.tests.nyc_bakery = function(test, common) { test('New York Bakery', function(t) { var doc = { - 'name': { 'default': 'New York Bakery' }, + 'name': 'New York Bakery', 'housenumber': '51 W', 'street': '29th', 'country_a': 'USA', @@ -203,7 +203,7 @@ module.exports.tests.nyc_bakery = function(test, common) { module.exports.tests.ferry_building = function(test, common) { test('Ferry Building', function(t) { var doc = { - 'name': { 'default': 'Ferry Building' }, + 'name': 'Ferry Building', 'country_a': 'USA', 'country': 'United States', 'region': 'California', diff --git a/test/unit/helper/labelGenerator_default.js b/test/unit/helper/labelGenerator_default.js index dc8ad02d..789233ba 100644 --- a/test/unit/helper/labelGenerator_default.js +++ b/test/unit/helper/labelGenerator_default.js @@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) { module.exports.tests.new_south_wales = function(test, common) { test('new south wales', function(t) { var doc = { - 'name': { 'default': 'New South Wales' }, + 'name': 'New South Wales', 'country_a': 'AUS', 'country': 'Australia', 'region': 'New South Wales' @@ -28,7 +28,7 @@ module.exports.tests.new_south_wales = function(test, common) { module.exports.tests.west_bengal = function(test, common) { test('west bengal', function(t) { var doc = { - 'name': { 'default': 'West Bengal' }, + 'name': 'West Bengal', 'country_a': 'IND', 'country': 'India', 'region': 'West Bengal' @@ -42,7 +42,7 @@ module.exports.tests.west_bengal = function(test, common) { module.exports.tests.bangalore = function(test, common) { test('bangalore', function(t) { var doc = { - 'name': { 'default': 'Bangalore' }, + 'name': 'Bangalore', 'country_a': 'IND', 'country': 'India', 'region': 'Karnataka', @@ -58,7 +58,7 @@ module.exports.tests.bangalore = function(test, common) { module.exports.tests.sarjapur = function(test, common) { test('Sarjapur', function(t) { var doc = { - 'name': { 'default': 'Sarjapur' }, + 'name': 'Sarjapur', 'country_a': 'IND', 'country': 'India', 'region': 'Karnataka' @@ -72,7 +72,7 @@ module.exports.tests.sarjapur = function(test, common) { module.exports.tests.bengaluru_east = function(test, common) { test('Bengaluru East', function(t) { var doc = { - 'name': { 'default': 'Bengaluru East' }, + 'name': 'Bengaluru East', 'country_a': 'IND', 'country': 'India', 'region': 'Karnataka', @@ -90,7 +90,7 @@ module.exports.tests.bengaluru_east = function(test, common) { module.exports.tests.wellington_victoria = function(test, common) { test('Wellington, Victoria, Australia', function(t) { var doc = { - 'name': { 'default': 'Wellington' }, + 'name': 'Wellington', 'country_a': 'AUS', 'country': 'Australia', 'region': 'Victoria', @@ -105,7 +105,7 @@ module.exports.tests.wellington_victoria = function(test, common) { module.exports.tests.arbil = function(test, common) { test('arbil', function(t) { var doc = { - 'name': { 'default': 'Arbil' }, + 'name': 'Arbil', 'country_a': 'IRQ', 'country': 'Iraq', 'region': 'Arbil' @@ -119,7 +119,7 @@ module.exports.tests.arbil = function(test, common) { module.exports.tests.madrid = function(test, common) { test('madrid', function(t) { var doc = { - 'name': { 'default': 'Madrid' }, + 'name': 'Madrid', 'country_a': 'ESP', 'country': 'Spain', 'region': 'Madrid' @@ -133,7 +133,7 @@ module.exports.tests.madrid = function(test, common) { module.exports.tests.one_grolmanstrasse = function(test, common) { test('one grolmanstrasse', function(t) { var doc = { - 'name': { 'default': '1 Grolmanstraße' }, + 'name': '1 Grolmanstraße', 'housenumber': '1', 'street': 'Grolmanstraße', 'postalcode': '10623', @@ -153,7 +153,7 @@ module.exports.tests.one_grolmanstrasse = function(test, common) { module.exports.tests.new_zealand = function(test, common) { test('new zealand', function(t) { var doc = { - 'name': { 'default': 'New Zealand' }, + 'name': 'New Zealand', 'country_a': 'NZL', 'country': 'New Zealand' }; @@ -166,7 +166,7 @@ module.exports.tests.new_zealand = function(test, common) { module.exports.tests.republic_of_ireland = function(test, common) { test('northern ireland', function(t) { var doc = { - 'name': { 'default': 'Ireland' }, + 'name': 'Ireland', 'country_a': 'IRL', 'country': 'Ireland' }; @@ -180,7 +180,7 @@ module.exports.tests.republic_of_ireland = function(test, common) { module.exports.tests.krabi_province = function(test, common) { test('Krabi Provence', function(t) { var doc = { - 'name': { 'default': 'Krabi' }, + 'name': 'Krabi', 'country_a': 'THA', 'country': 'Thailand', 'region': 'Krabi' @@ -194,7 +194,7 @@ module.exports.tests.krabi_province = function(test, common) { module.exports.tests.koh_lanta = function(test, common) { test('Koh Lanta', function(t) { var doc = { - 'name': { 'default': 'Ko Lanta' }, + 'name': 'Ko Lanta', 'country_a': 'THA', 'country': 'Thailand', 'region': 'Krabi' @@ -208,7 +208,7 @@ module.exports.tests.koh_lanta = function(test, common) { module.exports.tests.black_dog_cafe = function(test, common) { test('Black Dog Cafe', function(t) { var doc = { - 'name': { 'default': 'Black Dog Cafe' }, + 'name': 'Black Dog Cafe', 'country_a': 'NZL', 'country': 'New Zealand', 'region': 'Auckland Region', @@ -223,7 +223,7 @@ module.exports.tests.black_dog_cafe = function(test, common) { module.exports.tests.beach_bablyon = function(test, common) { test('Beach Bablyon', function(t) { var doc = { - 'name': { 'default': 'Beach Bablyon' }, + 'name': 'Beach Bablyon', 'country_a': 'NZL', 'country': 'New Zealand', 'region': 'Wellington Region', @@ -240,7 +240,7 @@ module.exports.tests.beach_bablyon = function(test, common) { module.exports.tests.waiotapu = function(test, common) { test('Waiotapu', function(t) { var doc = { - 'name': { 'default': 'Waiotapu' }, + 'name': 'Waiotapu', 'country_a': 'NZL', 'country': 'New Zealand', 'region': 'Bay of Plenty', diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 39d9c564..2f075940 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -14,8 +14,7 @@ module.exports.tests.interfaces = function(test, common) { t.deepEquals(type_mapping.layer_mapping.coarse, [ 'continent', 'macrocountry', 'country', 'dependency', 'region', 'locality', 'localadmin', 'county', 'macrohood', - 'neighbourhood', 'microhood', 'disputed', 'admin0', - 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin']); + 'neighbourhood', 'microhood', 'disputed' ]); t.end(); }); diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index bf454381..7d516f16 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/test/unit/middleware/confidenceScore.js @@ -70,13 +70,21 @@ module.exports.tests.confidenceScore = 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' + } }, { + _score: 20, value: 2, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, - admin0: 'country2', admin1: 'state2', admin2: 'city2', - _score: 20 + parent: { + country: 'country2', + region: 'state2', + county: 'city2' + } }], meta: {scores: [10]} }; diff --git a/test/unit/middleware/localNamingConventions.js b/test/unit/middleware/localNamingConventions.js index f3c877d0..da904e63 100644 --- a/test/unit/middleware/localNamingConventions.js +++ b/test/unit/middleware/localNamingConventions.js @@ -15,9 +15,11 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { 'number': '1', 'street': 'Main St' }, - 'admin1': 'Dungannon', - 'alpha3': 'GBR', - 'admin0': 'United Kingdom' + 'parent': { + 'region': 'Dungannon', + 'country_a': 'GBR', + 'country': 'United Kingdom' + } }; var deAddress = { @@ -30,12 +32,14 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { 'number': '23', 'street': 'Grolmanstraße' }, - 'admin1': 'Berlin', - 'locality': 'Berlin', - 'alpha3': 'DEU', - 'admin2': 'Berlin', - 'admin0': 'Germany', - 'neighborhood': 'Hansaviertel' + 'parent': { + 'region': 'Berlin', + 'locality': 'Berlin', + 'country_a': 'DEU', + 'county': 'Berlin', + 'country': 'Germany', + 'neighbourhood': 'Hansaviertel' + } }; var req = {}, diff --git a/test/unit/mock/backend.js b/test/unit/mock/backend.js index 7d0eb8d7..ea20c4d0 100644 --- a/test/unit/mock/backend.js +++ b/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' } } }])); }; diff --git a/test/unit/query/search.js b/test/unit/query/search.js index b468f493..f20122bb 100644 --- a/test/unit/query/search.js +++ b/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), }); @@ -142,8 +141,7 @@ module.exports.tests.query = function(test, common) { 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 +156,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), }); diff --git a/test/unit/sanitiser/_layers.js b/test/unit/sanitiser/_layers.js index bd499fc7..a1cdd7c5 100644 --- a/test/unit/sanitiser/_layers.js +++ b/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); diff --git a/test/unit/sanitiser/_sources.js b/test/unit/sanitiser/_sources.js index 61b2be90..b0daffef 100644 --- a/test/unit/sanitiser/_sources.js +++ b/test/unit/sanitiser/_sources.js @@ -29,7 +29,7 @@ module.exports.tests.no_sources = function(test, common) { }; var expected_error = 'sources parameter cannot be an empty string. ' + - 'Valid options: osm,oa,gn,qs,wof,openstreetmap,openaddresses,geonames,quattroshapes,whosonfirst'; + 'Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst'; var messages = sanitize(req.query, req.clean); @@ -104,7 +104,7 @@ module.exports.tests.invalid_sources = function(test, common) { var expected_messages = { errors: [ '\'notasource\' is an invalid sources parameter. ' + - 'Valid options: osm,oa,gn,qs,wof,openstreetmap,openaddresses,geonames,quattroshapes,whosonfirst' + 'Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst' ], warnings: [] }; diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index d42d87f4..5d599b0f 100644 --- a/test/unit/sanitiser/search.js +++ b/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 ){ diff --git a/test/unit/service/mget.js b/test/unit/service/mget.js index 9f13d78b..dd093c9f 100644 --- a/test/unit/service/mget.js +++ b/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' } } ]; diff --git a/test/unit/service/search.js b/test/unit/service/search.js index e5bf2cff..37eb93af 100644 --- a/test/unit/service/search.js +++ b/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' } } ];