Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude name for country result labels #633

Merged
merged 2 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment above probably has to be updated

}

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kinda concerned that we are taking the hierarchy country, and not the name of the record itself. Not really because of the effect it has, but just because of the precedent it sets (or has already been set and we are now continuing). In any case it may not matter if we decide to get rid of geonames in the near future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the name field but that would generate a label that we wouldn't be able to search for again. That is, geonames' name for China is The People's Republic of China. While libpostal understands it to be a country, we won't find anything since we only import the WOF name China.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think being able to search for a record using the label is important so in the interest of preserving that we should keep it this way for now. I imagine a lot of this will change when we start looking at Alt-Names and internationalization, so we can revisit it then and figure out the "right" approach.

t.end();
});

Expand Down