Browse Source

fix: Merge pull request #633 from pelias/fix-country-labels

exclude `name` for `country` result labels
pull/648/head v3.1.2
Julian Simioni 9 years ago committed by GitHub
parent
commit
270bcba8d3
  1. 13
      helper/labelGenerator.js
  2. 8
      test/unit/helper/labelGenerator_default.js

13
helper/labelGenerator.js

@ -47,8 +47,7 @@ function getSchema(country_a) {
} }
// helper function that sets a default label for non-US/CA regions // helper function that sets a default label for non-US/CA regions and countries
// this is a very special case
function getInitialLabel(record) { function getInitialLabel(record) {
if (isRegion(record.layer) && if (isRegion(record.layer) &&
isGeonamesOrWhosOnFirst(record.source) && isGeonamesOrWhosOnFirst(record.source) &&
@ -56,10 +55,20 @@ function getInitialLabel(record) {
return []; return [];
} }
if (isCountry(record.layer)) {
return [];
}
return [record.name]; 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) { function isRegion(layer) {
return 'region' === layer; return 'region' === layer;
} }

8
test/unit/helper/labelGenerator_default.js

@ -175,14 +175,14 @@ module.exports.tests.default_country = function(test, common) {
t.end(); t.end();
}); });
test('country', function(t) { test('country layer labels should only use the `country` field and not the `name`', function(t) {
var doc = { var doc = {
'name': 'country name', 'name': 'source country name',
'layer': 'country', 'layer': 'country',
'country_a': 'country code', '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(); t.end();
}); });

Loading…
Cancel
Save