Skip to content

Commit

Permalink
Merge pull request #1508 from pelias/improved-postcode-deduping
Browse files Browse the repository at this point in the history
Prefer records with postal code regardless of source
  • Loading branch information
orangejulius authored Feb 9, 2021
2 parents 7a262d0 + fc52f35 commit 0a964c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions middleware/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ function isPreferred(existingHit, candidateHit) {
// https://github.com/pelias/api/issues/872
if( !_.has(existingHit, 'address_parts.zip') &&
_.has(candidateHit, 'address_parts.zip') ){ return true; }
// if the existing hit HAS a postcode, and this candidate does NOT, keep the existing hit
if( _.has(existingHit, 'address_parts.zip') &&
!_.has(candidateHit, 'address_parts.zip') ){ return false; }

// prefer non-canonical sources over canonical ones
if( !_.includes(canonical_sources, candidateHit.source) &&
Expand Down
36 changes: 36 additions & 0 deletions test/unit/middleware/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,42 @@ module.exports.tests.priority = function(test, common) {
});
});

test('osm with zip takes priority over openaddresses without zip, regardless of order of results', function (t) {
var req = {
clean: {
text: '100 Main St',
size: 100
}
};
var res = {
data: [
{
'name': { 'default': '100 Main St' },
'source': 'openstreetmap',
'source_id': '654321',
'layer': 'address',
'address_parts': {
'zip': '54321'
}
},
{
'name': { 'default': '100 Main St' },
'source': 'openaddresses',
'source_id': '123456',
'layer': 'address',
'address_parts': {}
},
]
};

var expectedCount = 1;
dedupe(req, res, function () {
t.equal(res.data.length, expectedCount, 'results have fewer items than before');
t.deepEqual(res.data[0].source_id, '654321', 'openstreetmap result with zip won');
t.end();
});
});

test('works with name aliases', function (t) {
var req = {
clean: {
Expand Down

0 comments on commit 0a964c2

Please sign in to comment.