From 7b5b9dee61b378ec1e99637ead4956e1eff02d3b Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 1 Mar 2016 17:04:43 -0500 Subject: [PATCH] added comments illustrating the subtleties of label generation --- helper/labelGenerator.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/helper/labelGenerator.js b/helper/labelGenerator.js index 3e4a4237..c9eff405 100644 --- a/helper/labelGenerator.js +++ b/helper/labelGenerator.js @@ -24,7 +24,28 @@ module.exports = function( record ){ } // de-dupe, join, trim + // NOTE: while it may seem odd to call `uniq` on the list of label parts, + // the effect is quite subtle. Take, for instance, a result for "Lancaster, PA" + // the pseudo-object is: + // { + // 'name': 'Lancaster', + // 'locality': 'Lancaster', + // 'region_a': 'PA', + // 'country_a': 'USA' + // } + // + // the code up to this point generates the label: + // `Lancaster, Lancaster, PA, USA` + // + // then the `unique` call reduces this to: + // `Lancaster, PA, USA` + // + // this code doesn't have the same effect in the case of a venue or address + // where the `name` field would contain the address or name of a point-of-interest + // + // Also see https://github.com/pelias/api/issues/429 for other ways that this is bad return _.uniq( labelParts ).join(', ').trim(); + }; function getSchema(country_a) {