Skip to content

Commit

Permalink
fix: Merge pull request #633 from pelias/fix-country-labels
Browse files Browse the repository at this point in the history
exclude `name` for `country` result labels
  • Loading branch information
orangejulius authored Aug 19, 2016
2 parents 49b4857 + a090a1e commit 270bcba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions helper/labelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ 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) &&
isUSAOrCAN(record.country_a)) {
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;
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/helper/labelGenerator_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 270bcba

Please sign in to comment.