From 1b83247964090597f05ce9d2ca14a7c4c412cf00 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Fri, 12 Aug 2016 13:31:05 -0400 Subject: [PATCH 1/2] exclude `name` for `country` result labels --- helper/labelGenerator.js | 10 ++++++++++ test/unit/helper/labelGenerator_default.js | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/helper/labelGenerator.js b/helper/labelGenerator.js index 97993e03..a7894896 100644 --- a/helper/labelGenerator.js +++ b/helper/labelGenerator.js @@ -56,10 +56,20 @@ function getInitialLabel(record) { return []; } + if (isCountry(record.layer)) { + return []; + } + return [record.name]; } +// this can go away once geonames is no longer supported +// https://github.com/pelias/wof-admin-lookup/issues/49 +function isCountry(layer) { + return 'country' === layer; +} + function isRegion(layer) { return 'region' === layer; } diff --git a/test/unit/helper/labelGenerator_default.js b/test/unit/helper/labelGenerator_default.js index 25991ab8..4679f136 100644 --- a/test/unit/helper/labelGenerator_default.js +++ b/test/unit/helper/labelGenerator_default.js @@ -175,14 +175,14 @@ module.exports.tests.default_country = function(test, common) { t.end(); }); - test('country', function(t) { + test('country layer labels should only use the `country` field and not the `name`', function(t) { var doc = { - 'name': 'country name', + 'name': 'source country name', 'layer': 'country', 'country_a': 'country code', - 'country': 'country name' + 'country': 'hierarchy country name' }; - t.equal(generator(doc),'country name'); + t.equal(generator(doc),'hierarchy country name'); t.end(); }); From a090a1e71a0d748d5e167625f0289aa57fa14a03 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Fri, 12 Aug 2016 13:46:09 -0400 Subject: [PATCH 2/2] updated comment --- helper/labelGenerator.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helper/labelGenerator.js b/helper/labelGenerator.js index a7894896..34112157 100644 --- a/helper/labelGenerator.js +++ b/helper/labelGenerator.js @@ -47,8 +47,7 @@ function getSchema(country_a) { } -// helper function that sets a default label for non-US/CA regions -// this is a very special case +// helper function that sets a default label for non-US/CA regions and countries function getInitialLabel(record) { if (isRegion(record.layer) && isGeonamesOrWhosOnFirst(record.source) &&