Browse Source

Improve response deduping

Consider locality and neighborhood, too. Do not take absence of
an attribute as a difference.
pull/444/head
Vesa Meskanen 9 years ago
parent
commit
0e6bf8ed00
  1. 12
      middleware/dedupe.js

12
middleware/dedupe.js

@ -42,13 +42,17 @@ function isDifferent(item1, item2) {
if (item1.hasOwnProperty('parent') && item2.hasOwnProperty('parent')) {
propMatch(item1.parent, item2.parent, 'region_a');
propMatch(item1.parent, item2.parent, 'country');
propMatch(item1.parent, item2.parent, 'locality');
propMatch(item1.parent, item2.parent, 'neighborhood');
}
else if (item1.parent !== item2.parent) {
throw new Error('different');
}
if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) {
propMatch(item1.name, item2.name, 'default');
for (var lang in item1.name) {
propMatch(item1.name, item2.name, lang);
}
}
else {
propMatch(item1, item2, 'name');
@ -92,6 +96,10 @@ function propMatch(item1, item2, prop) {
prop2= prop2[0];
}
if (!prop1 || !prop2) {
return; // absence of information does not make an item different
}
if (normalizeString(prop1) !== normalizeString(prop2)) {
throw new Error('different');
}
@ -111,4 +119,4 @@ function normalizeString(str) {
}
module.exports = setup;
module.exports = setup;

Loading…
Cancel
Save