Browse Source

Merge branch 'master' into expose-bbox

pull/443/head
Diana Shkolnikov 9 years ago
parent
commit
5e906d4dfe
  1. 10
      middleware/confidenceScore.js
  2. 2
      middleware/localNamingConventions.js
  3. 12
      test/unit/controller/search.js
  4. 30
      test/unit/fixture/dedupe_elasticsearch_nonascii_results.js
  5. 168
      test/unit/fixture/dedupe_elasticsearch_results.js
  6. 12
      test/unit/middleware/confidenceScore.js
  7. 18
      test/unit/middleware/localNamingConventions.js
  8. 8
      test/unit/mock/backend.js
  9. 4
      test/unit/service/mget.js
  10. 4
      test/unit/service/search.js

10
middleware/confidenceScore.js

@ -95,7 +95,7 @@ function checkForDealBreakers(req, hit) {
return false;
}
if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a) {
if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a[0]) {
logger.debug('[confidence][deal-breaker]: state !== region_a');
return true;
}
@ -210,8 +210,8 @@ function propMatch(textProp, hitProp, expectEnriched) {
* @param {string|number} [hit.address.number]
* @param {string} [hit.address.street]
* @param {string|number} [hit.address.zip]
* @param {string} [hit.parent.region_a]
* @param {string} [hit.parent.country_a]
* @param {Array} [hit.parent.region_a]
* @param {Array} [hit.parent.country_a]
* @returns {number}
*/
function checkAddress(text, hit) {
@ -222,8 +222,8 @@ function checkAddress(text, hit) {
res += propMatch(text.number, (hit.address ? hit.address.number : null), false);
res += propMatch(text.street, (hit.address ? hit.address.street : null), false);
res += propMatch(text.postalcode, (hit.address ? hit.address.zip: null), true);
res += propMatch(text.state, hit.parent.region_a, true);
res += propMatch(text.country, hit.parent.country_a, true);
res += propMatch(text.state, hit.parent.region_a[0], true);
res += propMatch(text.country, hit.parent.country_a[0], true);
res /= checkCount;
}

2
middleware/localNamingConventions.js

@ -13,7 +13,7 @@ function applyLocalNamingConventions(req, res, next) {
// loop through data items and flip relevant number/street
res.data.filter(function(place){
// only relevant for German addresses
if( 'DEU' !== place.parent.country_a ){ return false; }
if( place.parent.country_a.indexOf('DEU') === -1 ){ return false; }
if( !place.hasOwnProperty('address') ){ return false; }
if( !place.address.hasOwnProperty('number') ){ return false; }
if( !place.address.hasOwnProperty('street') ){ return false; }

12
test/unit/controller/search.js

@ -51,9 +51,9 @@ module.exports.tests.functional_success = function(test, common) {
_score: 10,
_type: 'mytype1',
parent: {
country: 'country1',
region: 'state1',
county: 'city1'
country: ['country1'],
region: ['state1'],
county: ['city1']
},
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
@ -64,9 +64,9 @@ module.exports.tests.functional_success = function(test, common) {
_score: 20,
_type: 'mytype2',
parent: {
country: 'country2',
region: 'state2',
county: 'city2'
country: ['country2'],
region: ['state2'],
county: ['city2']
},
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },

30
test/unit/fixture/dedupe_elasticsearch_nonascii_results.js

@ -8,9 +8,9 @@ module.exports = [
'default': '万里长城万里长城'
},
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing'
'country_a': ['CHN'],
'country': ['China'],
'region': ['Beijing']
},
'confidence': 0.733
},
@ -23,9 +23,9 @@ module.exports = [
'default': '万里长城'
},
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Beijing'
'country_a': ['CHN'],
'country': ['China'],
'region': ['Beijing']
},
'confidence': 0.733
},
@ -38,12 +38,12 @@ module.exports = [
'default': '万里花'
},
'parent': {
'country_a': 'JPN',
'country': 'Japan',
'region': 'Tokyo',
'county': '豊島区',
'locality': 'Tokyo',
'neighbourhood': '2丁目'
'country_a': ['JPN'],
'country': ['Japan'],
'region': ['Tokyo'],
'county': ['豊島区'],
'locality': ['Tokyo'],
'neighbourhood': ['2丁目']
},
'confidence': 0.646
},
@ -60,9 +60,9 @@ module.exports = [
'postalcode': '312044'
},
'parent': {
'country_a': 'CHN',
'country': 'China',
'region': 'Zhejiang'
'country_a': ['CHN'],
'country': ['China'],
'region': ['Zhejiang']
},
'confidence': 0.646
}

168
test/unit/fixture/dedupe_elasticsearch_results.js

@ -6,14 +6,14 @@ module.exports = [
},
'address': {},
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
'localadmin': ['East Lampeter'],
'region_a': ['PA'],
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland']
},
'name': {
'default': 'East Lampeter High School'
@ -33,14 +33,14 @@ module.exports = [
},
'address': {},
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
'localadmin': ['East Lampeter'],
'region_a': ['PA'],
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland']
},
'name': {
'default': 'East Lampeter, High-School'
@ -60,14 +60,14 @@ module.exports = [
},
'address': {},
'parent': {
'localadmin': 'West Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills'
'localadmin': ['West Lampeter'],
'region_a': ['PA'],
'region': ['Pennsylvania'],
'locality': ['Lampeter'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Wheatland Mills']
},
'name': {
'default': 'Lampeter-Strasburg High School'
@ -87,14 +87,14 @@ module.exports = [
},
'address': {},
'parent': {
'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
'localadmin': ['East Lampeter'],
'region_a': ['PA'],
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland']
},
'name': {
'default': 'East Lampeter High School'
@ -114,14 +114,14 @@ module.exports = [
},
'address': {},
'parent': {
'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills',
'localadmin': 'West Lampeter',
'region_a': 'PA'
'region': ['Pennsylvania'],
'locality': ['Lampeter'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Wheatland Mills'],
'localadmin': ['West Lampeter'],
'region_a': ['PA']
},
'name': {
'default': 'Lampeter-Strasburg High School'
@ -141,14 +141,14 @@ module.exports = [
},
'address': {},
'parent': {
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland'],
'localadmin': ['East Lampeter'],
'region_a': ['PA']
},
'name': {
'default': 'East Lampeter School'
@ -168,14 +168,14 @@ module.exports = [
},
'address': {},
'parent': {
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland'],
'localadmin': ['East Lampeter'],
'region_a': ['PA']
},
'name': {
'default': 'East Lampeter School'
@ -195,13 +195,13 @@ module.exports = [
},
'address': {},
'parent': {
'region': 'Missouri',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Cass County',
'country': 'United States',
'localadmin': 'Polk',
'region_a': 'MO'
'region': ['Missouri'],
'locality': ['Strasburg'],
'country_a': ['USA'],
'county': ['Cass County'],
'country': ['United States'],
'localadmin': ['Polk'],
'region_a': ['MO']
},
'name': {
'default': 'Strasburg School'
@ -224,13 +224,13 @@ module.exports = [
'default': 'Strasburg High School'
},
'parent': {
'region_a': 'VA',
'region': 'Virginia',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Shenandoah County',
'country': 'United States',
'neighbourhood': 'Strasburg Junction'
'region_a': ['VA'],
'region': ['Virginia'],
'locality': ['Strasburg'],
'country_a': ['USA'],
'county': ['Shenandoah County'],
'country': ['United States'],
'neighbourhood': ['Strasburg Junction']
},
'category': [
'education'
@ -250,13 +250,13 @@ module.exports = [
'default': 'Strasburg High School'
},
'parent': {
'localadmin': 'Strasburg',
'region_a': 'ND',
'region': 'North Dakota',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Emmons County',
'country': 'United States'
'localadmin': ['Strasburg'],
'region_a': ['ND'],
'region': ['North Dakota'],
'locality': ['Strasburg'],
'country_a': ['USA'],
'county': ['Emmons County'],
'country': ['United States']
},
'category': [
'education'
@ -276,13 +276,13 @@ module.exports = [
'default': 'Strasburg High School'
},
'parent': {
'localadmin': 'Franklin',
'region_a': 'OH',
'region': 'Ohio',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Tuscarawas County',
'country': 'United States'
'localadmin': ['Franklin'],
'region_a': ['OH'],
'region': ['Ohio'],
'locality': ['Strasburg'],
'country_a': ['USA'],
'county': ['Tuscarawas County'],
'country': ['United States']
},
'category': [
'education'

12
test/unit/middleware/confidenceScore.js

@ -71,9 +71,9 @@ module.exports.tests.confidenceScore = function(test, common) {
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: 'country1',
region: 'state1',
county: 'city1'
country: ['country1'],
region: ['state1'],
county: ['city1']
}
}, {
_score: 20,
@ -81,9 +81,9 @@ module.exports.tests.confidenceScore = function(test, common) {
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: {
country: 'country2',
region: 'state2',
county: 'city2'
country: ['country2'],
region: ['state2'],
county: ['city2']
}
}],
meta: {scores: [10]}

18
test/unit/middleware/localNamingConventions.js

@ -16,9 +16,9 @@ module.exports.tests.flipNumberAndStreet = function(test, common) {
'street': 'Main St'
},
'parent': {
'region': 'Dungannon',
'country_a': 'GBR',
'country': 'United Kingdom'
'region': ['Dungannon'],
'country_a': ['GBR'],
'country': ['United Kingdom']
}
};
@ -33,12 +33,12 @@ module.exports.tests.flipNumberAndStreet = function(test, common) {
'street': 'Grolmanstraße'
},
'parent': {
'region': 'Berlin',
'locality': 'Berlin',
'country_a': 'DEU',
'county': 'Berlin',
'country': 'Germany',
'neighbourhood': 'Hansaviertel'
'region': ['Berlin'],
'locality': ['Berlin'],
'country_a': ['DEU'],
'county': ['Berlin'],
'country': ['Germany'],
'neighbourhood': ['Hansaviertel']
}
};

8
test/unit/mock/backend.js

@ -15,7 +15,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' }
parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
}
}, {
_id: 'myid2',
@ -25,7 +25,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' }
parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
}
}]));
};
@ -43,7 +43,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' }
parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
}
}, {
_id: 'myid2',
@ -54,7 +54,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' }
parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
}
}]));
};

4
test/unit/service/mget.js

@ -20,14 +20,14 @@ module.exports.tests.functional_success = function(test, common) {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' }
parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
},
{
_id: 'myid2', _type: 'mytype2',
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' }
parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
}
];

4
test/unit/service/search.js

@ -23,7 +23,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' }
parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
},
{
_id: 'myid2', _type: 'mytype2',
@ -31,7 +31,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' }
parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
}
];

Loading…
Cancel
Save