From f18e278e51df9e79e2911d79c2675eea52dcd14f Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 25 Jul 2016 15:20:42 -0400 Subject: [PATCH 1/3] Handle case where record has no region_ a field --- middleware/confidenceScore.js | 2 +- test/unit/middleware/confidenceScore.js | 30 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index 39ea45b2..71a39bad 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -93,7 +93,7 @@ function checkForDealBreakers(req, hit) { return false; } - if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a[0]) { + if (check.assigned(req.clean.parsed_text.state) && hit.parent.region_a && req.clean.parsed_text.state !== hit.parent.region_a[0]) { logger.debug('[confidence][deal-breaker]: state !== region_a'); return true; } diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index f629874b..e9b80177 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/test/unit/middleware/confidenceScore.js @@ -94,6 +94,36 @@ module.exports.tests.confidenceScore = function(test, common) { t.end(); }); + test('undefined region fields should be handled gracefully', function(t) { + var req = { + clean: { + text: 'test name1, TX', + parsed_text: { + state: 'TX' + } + } + }; + var res = { + data: [{ + _score: 10, + found: true, + value: 1, + center_point: { lat: 100.1, lon: -50.5 }, + name: { default: 'test name1' }, + parent: { + country: ['country1'], + region: undefined, + region_a: undefined, + county: ['city1'] + } + }], + meta: {scores: [10]} + }; + + confidenceScore(req, res, function() {}); + t.equal(res.data[0].confidence, 0.54, 'score was set'); + t.end(); + }); }; module.exports.all = function (tape, common) { From 8cae743c80a5e638d53abd0146d44eb2efc40358 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 25 Jul 2016 15:24:14 -0400 Subject: [PATCH 2/3] Handle empty country_a values as well --- middleware/confidenceScore.js | 4 ++-- test/unit/middleware/confidenceScore.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index 71a39bad..2e9eb1c6 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -219,8 +219,8 @@ function checkAddress(text, hit) { res += propMatch(text.number, (hit.address_parts ? hit.address_parts.number : null), false); res += propMatch(text.street, (hit.address_parts ? hit.address_parts.street : null), false); res += propMatch(text.postalcode, (hit.address_parts ? hit.address_parts.zip: null), true); - res += propMatch(text.state, hit.parent.region_a[0], true); - res += propMatch(text.country, hit.parent.country_a[0], true); + res += propMatch(text.state, (hit.parent.region_a ? hit.parent.region_a[0] : null), true); + res += propMatch(text.country, (hit.parent.country_a ? hit.parent.country_a[0] :null), true); res /= checkCount; } diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index e9b80177..7d6ba87d 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/test/unit/middleware/confidenceScore.js @@ -97,9 +97,11 @@ module.exports.tests.confidenceScore = function(test, common) { test('undefined region fields should be handled gracefully', function(t) { var req = { clean: { - text: 'test name1, TX', + text: '123 Main St, City, NM', parsed_text: { - state: 'TX' + number: 123, + street: 'Main St', + state: 'NM' } } }; @@ -121,7 +123,7 @@ module.exports.tests.confidenceScore = function(test, common) { }; confidenceScore(req, res, function() {}); - t.equal(res.data[0].confidence, 0.54, 'score was set'); + t.equal(res.data[0].confidence, 0.28, 'score was set'); t.end(); }); }; From c210b50c119de11cedef47ab841f40c365db92ae Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 27 Jul 2016 11:18:01 -0700 Subject: [PATCH 3/3] chore(package): update pelias-text-analyzer to version 1.2.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3a3d01a..19314d04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "pelias-logger": "0.0.8", "pelias-model": "4.1.0", "pelias-query": "8.1.3", - "pelias-text-analyzer": "1.1.0", + "pelias-text-analyzer": "1.2.0", "stats-lite": "2.0.3", "through2": "2.0.1" },