@@ -5,17 +5,20 @@ var stringUtils = require('../helper/stringUtils');
55var normalize = stringUtils . normalize ;
66var removeSpaces = stringUtils . removeSpaces ;
77
8+ const areaLikes = [ 'venue' , 'neighbourhood' , 'localadmin' ] ;
9+
810module . exports = function ( record , req ) {
911 var schemaId = _ . get ( record , [ 'parent' , 'country_a' , 0 ] , 'FIN' ) ;
1012 var schema = getSchema ( schemaId ) ;
1113
1214 // in virtually all cases, this will be the `name` field
1315 var labelParts = getInitialLabel ( record ) ;
14-
16+ // do not add neighbourhood to largish area-like items
17+ const skip = record . category ?. includes ( 'populated area' ) ? 'neighbourhood' : null ;
1518 // iterate the schema
1619 for ( var field in schema ) {
1720 var valueFunction = schema [ field ] ;
18- var value = valueFunction ( record , req ) ;
21+ var value = valueFunction ( record , req , skip ) ;
1922 if ( value ) {
2023 labelParts . push ( value ) ;
2124 }
@@ -25,18 +28,21 @@ module.exports = function( record, req ){
2528 labelParts = _ . compact ( labelParts ) ;
2629
2730 // third, dedupe and join with a comma and return
28- return dedupeNameAndFirstLabelElement ( labelParts ) . join ( ', ' ) ;
29-
31+ const candDropMinorAdmin = areaLikes . includes ( record . layer ) ;
32+ return dedupeNameAndFirstLabelElement ( labelParts , candDropMinorAdmin ) . join ( ', ' ) ;
3033} ;
3134
32- function dedupeNameAndFirstLabelElement ( labelParts ) {
35+ function dedupeNameAndFirstLabelElement ( labelParts , dropMinorAdmin ) {
3336 // only dedupe if a result has more than a name (the first label part)
3437 if ( labelParts . length > 1 ) {
3538 // first, dedupe the name and 1st label array elements
36- // this is used to ensure that the `name` and first admin hierarchy elements aren't repeated
37- // eg - `["Lancaster", "Lancaster", "PA", "United States"]` -> `["Lancaster", "PA", "United States"]`
38-
39- if ( labelParts [ 0 ] . toLowerCase ( ) === labelParts [ 1 ] . toLowerCase ( ) ) {
39+ // this is used to ensure that the `name` and first admin hierarchy elements aren't repeated
40+ // eg - `["Lancaster", "Lancaster", "PA", "United States"]` -> `["Lancaster", "PA", "United States"]`
41+ // also, do not add a minor admin to a name of coarser admin, e.g. helsinki, kaartinkaupunki, helsinki
42+ if (
43+ labelParts [ 0 ] . toLowerCase ( ) === labelParts [ 1 ] . toLowerCase ( ) ||
44+ dropMinorAdmin && labelParts . length > 2 && labelParts [ 0 ] . toLowerCase ( ) === labelParts [ 2 ] . toLowerCase ( )
45+ ) {
4046 labelParts . splice ( 1 , 1 ) ;
4147 }
4248 }
0 commit comments