@@ -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
@@ -186,11 +187,43 @@ function isAddressDifferent(item1, item2){
186187 return false ;
187188}
188189
190+ function isGeonamesConcordanceSame ( item1 , item2 ) {
191+ let wof_record ;
192+ let gn_record ;
193+
194+ if ( item1 . source === 'geonames' && item2 . source === 'whosonfirst' ) {
195+ gn_record = item1 ;
196+ wof_record = item2 ;
197+ } else if ( item2 . source === 'geonames' && item1 . source === 'whosonfirst' ) {
198+ gn_record = item2 ;
199+ wof_record = item1 ;
200+ } else {
201+ // could not match to one geonames and one wof concordance, so this check does not apply
202+ return false ;
203+ }
204+
205+ const concordances = _ . get ( wof_record , 'addendum.concordances' ) ;
206+
207+ if ( concordances ) {
208+ const json = codec . decode ( concordances ) ;
209+ const concordance_id = json [ 'gn:id' ] ;
210+
211+ if ( concordance_id && typeof concordance_id === 'number' && concordance_id . toString ( ) === gn_record . source_id ) {
212+ return true ;
213+ }
214+ }
215+
216+ return false ;
217+ }
218+
189219/**
190220 * Compare the two records and return true if they differ and false if same.
191221 * Optionally provide $requestLanguage (req.clean.lang.iso6393) to improve name deduplication.
192222 */
193223function isDifferent ( item1 , item2 , requestLanguage ) {
224+ // records that share a geonames concordance are the same, regardless of any other checks
225+ if ( isGeonamesConcordanceSame ( item1 , item2 ) ) { return false ; }
226+
194227 if ( isLayerDifferent ( item1 , item2 ) ) { return true ; }
195228 if ( isParentHierarchyDifferent ( item1 , item2 ) ) { return true ; }
196229 if ( isNameDifferent ( item1 , item2 , requestLanguage ) ) { return true ; }
0 commit comments