From 916e7d673617bc299b125ec875bb72dccdfe1553 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Wed, 26 Oct 2016 11:52:35 -0400 Subject: [PATCH] made `locality` and `localadmin` equivalent in fallback scoring --- middleware/confidenceScoreFallback.js | 4 +- .../middleware/confidenceScoreFallback.js | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/middleware/confidenceScoreFallback.js b/middleware/confidenceScoreFallback.js index d10d3ade..d208d02f 100644 --- a/middleware/confidenceScoreFallback.js +++ b/middleware/confidenceScoreFallback.js @@ -72,13 +72,13 @@ function checkFallbackLevel(req, hit) { return 0.8; case 'street': return 0.8; + case 'localadmin': case 'locality': case 'borough': case 'neighbourhood': return 0.6; case 'macrocounty': case 'county': - case 'localadmin': return 0.4; case 'region': return 0.3; @@ -99,7 +99,7 @@ function checkFallbackLevel(req, hit) { function checkFallbackOccurred(req, hit) { return (requestedAddress(req) && hit.layer !== 'address') || (requestedStreet(req) && hit.layer !== 'street') || - (requestedCity(req) && hit.layer !== 'locality'); + (requestedCity(req) && hit.layer !== 'locality' && hit.layer !== 'localadmin'); } function requestedAddress(req) { diff --git a/test/unit/middleware/confidenceScoreFallback.js b/test/unit/middleware/confidenceScoreFallback.js index 1adf77da..138bee8c 100644 --- a/test/unit/middleware/confidenceScoreFallback.js +++ b/test/unit/middleware/confidenceScoreFallback.js @@ -203,6 +203,40 @@ module.exports.tests.confidenceScore = function(test, common) { t.end(); }); + test('fallback to localadmin should have score deduction', function(t) { + var req = { + clean: { + text: '123 Main St, City, NM', + parsed_text: { + number: 123, + street: 'Main St', + state: 'NM' + } + } + }; + var res = { + data: [{ + _score: 10, + found: true, + value: 1, + layer: 'localadmin', + center_point: { lat: 100.1, lon: -50.5 }, + name: { default: 'test name1' }, + parent: { + country: ['country1'] + } + }], + meta: { + scores: [10], + query_type: 'fallback' + } + }; + + confidenceScore(req, res, function() {}); + t.equal(res.data[0].confidence, 0.6, 'score was set'); + t.end(); + }); + test('fallback to country should have score deduction', function(t) { var req = { clean: { @@ -261,6 +295,29 @@ module.exports.tests.confidenceScore = function(test, common) { t.end(); }); + test('city input granularity with localadmin result should set score to 1.0', function(t) { + var req = { + clean: { + parsed_text: { + city: 'city name', + state: 'state name' + } + } + }; + var res = { + data: [{ + layer: 'localadmin' + }], + meta: { + query_type: 'fallback' + } + }; + + confidenceScore(req, res, function() {}); + t.equal(res.data[0].confidence, 1.0, 'score was set'); + t.end(); + }); + test('city input granularity with region fallback should set score to 0.3', function(t) { var req = { clean: {