@@ -4,6 +4,7 @@ const unicode = require('./unicode');
44const placeTypes = require ( './placeTypes' ) ;
55const canonicalLayers = require ( '../helper/type_mapping' ) . getCanonicalLayers ( ) ;
66const field = require ( '../helper/fieldValue' ) ;
7+ const codec = require ( 'pelias-model' ) . codec ;
78
89// only consider these layers as synonymous for deduplication purposes.
910// when performing inter-layer deduping, layers coming earlier in this list take
@@ -169,11 +170,43 @@ function isAddressDifferent(item1, item2){
169170 return false ;
170171}
171172
173+ function isGeonamesConcordanceSame ( item1 , item2 ) {
174+ let wof_record ;
175+ let gn_record ;
176+
177+ if ( item1 . source === 'geonames' && item2 . source === 'whosonfirst' ) {
178+ gn_record = item1 ;
179+ wof_record = item2 ;
180+ } else if ( item2 . source === 'geonames' && item1 . source === 'whosonfirst' ) {
181+ gn_record = item2 ;
182+ wof_record = item1 ;
183+ } else {
184+ // could not match to one geonames and one wof concordance, so this check does not apply
185+ return false ;
186+ }
187+
188+ const concordances = _ . get ( wof_record , 'addendum.concordances' ) ;
189+
190+ if ( concordances ) {
191+ const json = codec . decode ( concordances ) ;
192+ const concordance_id = json [ 'gn:id' ] ;
193+
194+ if ( concordance_id && typeof concordance_id === 'number' && concordance_id . toString ( ) === gn_record . source_id ) {
195+ return true ;
196+ }
197+ }
198+
199+ return false ;
200+ }
201+
172202/**
173203 * Compare the two records and return true if they differ and false if same.
174204 * Optionally provide $requestLanguage (req.clean.lang.iso6393) to improve name deduplication.
175205 */
176206function isDifferent ( item1 , item2 , requestLanguage ) {
207+ // records that share a geonames concordance are the same, regardless of any other checks
208+ if ( isGeonamesConcordanceSame ( item1 , item2 ) ) { return false ; }
209+
177210 if ( isLayerDifferent ( item1 , item2 ) ) { return true ; }
178211 if ( isParentHierarchyDifferent ( item1 , item2 ) ) { return true ; }
179212 if ( isNameDifferent ( item1 , item2 , requestLanguage ) ) { return true ; }
0 commit comments