|
|
@ -4,6 +4,10 @@ const isDifferent = require('../helper/diffPlaces').isDifferent; |
|
|
|
const canonical_sources = require('../helper/type_mapping').canonical_sources; |
|
|
|
const canonical_sources = require('../helper/type_mapping').canonical_sources; |
|
|
|
const field = require('../helper/fieldValue'); |
|
|
|
const field = require('../helper/fieldValue'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// when performing inter-layer deduping, layers coming earlier in this list take
|
|
|
|
|
|
|
|
// preference to those appearing later or not at all.
|
|
|
|
|
|
|
|
const layerPreferences = [ 'locality', 'country', 'localadmin', 'region', 'neighbourhood' ]; |
|
|
|
|
|
|
|
|
|
|
|
function dedupeResults(req, res, next) { |
|
|
|
function dedupeResults(req, res, next) { |
|
|
|
|
|
|
|
|
|
|
|
// do nothing if request data is invalid
|
|
|
|
// do nothing if request data is invalid
|
|
|
@ -79,19 +83,28 @@ function isPreferred(existingHit, candidateHit) { |
|
|
|
if( !_.includes(canonical_sources, candidateHit.source) && |
|
|
|
if( !_.includes(canonical_sources, candidateHit.source) && |
|
|
|
_.includes(canonical_sources, existingHit.source) ){ return true; } |
|
|
|
_.includes(canonical_sources, existingHit.source) ){ return true; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// prefer certain layers over others
|
|
|
|
|
|
|
|
if( existingHit.layer !== candidateHit.layer && _.isArray( layerPreferences ) ){ |
|
|
|
|
|
|
|
for( let i=0; i<layerPreferences.length; i++ ){ |
|
|
|
|
|
|
|
if( existingHit.layer === layerPreferences[i] ){ return false; } |
|
|
|
|
|
|
|
if( candidateHit.layer === layerPreferences[i] ){ return true; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// prefer certain sources over others
|
|
|
|
// prefer certain sources over others
|
|
|
|
switch( existingHit.source ){ |
|
|
|
if( existingHit.source !== candidateHit.source ){ |
|
|
|
// sources are the same
|
|
|
|
switch( existingHit.source ){ |
|
|
|
case candidateHit.source: return false; |
|
|
|
// WOF has bbox and is generally preferred
|
|
|
|
// WOF has bbox and is generally preferred
|
|
|
|
case 'geonames': return candidateHit.source === 'whosonfirst'; |
|
|
|
case 'geonames': return candidateHit.source === 'whosonfirst'; |
|
|
|
// addresses are generally better in OA
|
|
|
|
// addresses are generally better in OA
|
|
|
|
case 'openstreetmap': return candidateHit.source === 'openaddresses'; |
|
|
|
case 'openstreetmap': return candidateHit.source === 'openaddresses'; |
|
|
|
// venues are better in OSM
|
|
|
|
// venues are better in OSM
|
|
|
|
case 'whosonfirst': return candidateHit.source === 'openstreetmap'; |
|
|
|
case 'whosonfirst': return candidateHit.source === 'openstreetmap'; |
|
|
|
} |
|
|
|
// no preference, keep existing hit
|
|
|
|
|
|
|
|
default: return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// no preference, keep existing hit
|
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function() { |
|
|
|
module.exports = function() { |
|
|
|