Browse Source

added city input/results support

just uses the original scoring, which is open to debate
pull/705/head
Stephen Hess 8 years ago
parent
commit
c3451bbec0
  1. 11
      middleware/confidenceScoreFallback.js
  2. 71
      test/unit/middleware/confidenceScoreFallback.js

11
middleware/confidenceScoreFallback.js

@ -89,6 +89,7 @@ function checkFallbackLevel(req, hit) {
default: default:
return 0.1; return 0.1;
} }
} }
hit.match_type = 'exact'; hit.match_type = 'exact';
@ -96,11 +97,9 @@ function checkFallbackLevel(req, hit) {
} }
function checkFallbackOccurred(req, hit) { function checkFallbackOccurred(req, hit) {
// at this time we only do this for address queries, so keep this simple
// TODO: add other layer checks once we start handling disambiguation
return (requestedAddress(req) && hit.layer !== 'address') || return (requestedAddress(req) && hit.layer !== 'address') ||
(requestedStreet(req) && hit.layer !== 'street'); (requestedStreet(req) && hit.layer !== 'street') ||
(requestedCity(req) && hit.layer !== 'locality');
} }
function requestedAddress(req) { function requestedAddress(req) {
@ -115,4 +114,8 @@ function requestedStreet(req) {
req.clean.parsed_text.hasOwnProperty('street'); req.clean.parsed_text.hasOwnProperty('street');
} }
function requestedCity(req) {
return req.clean.parsed_text.hasOwnProperty('city');
}
module.exports = setup; module.exports = setup;

71
test/unit/middleware/confidenceScoreFallback.js

@ -237,6 +237,77 @@ module.exports.tests.confidenceScore = function(test, common) {
t.equal(res.data[0].confidence, 0.1, 'score was set'); t.equal(res.data[0].confidence, 0.1, 'score was set');
t.end(); t.end();
}); });
test('city input granularity with locality result should set score to 1.0', function(t) {
var req = {
clean: {
parsed_text: {
city: 'city name',
state: 'state name'
}
}
};
var res = {
data: [{
layer: 'locality'
}],
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: {
parsed_text: {
city: 'city name',
state: 'state name'
}
}
};
var res = {
data: [{
layer: 'region'
}],
meta: {
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.3, 'score was set');
t.end();
});
test('city input granularity with country fallback should set score to 0.1', function(t) {
var req = {
clean: {
parsed_text: {
city: 'city name',
state: 'state name',
country: 'country name'
}
}
};
var res = {
data: [{
layer: 'country'
}],
meta: {
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.1, 'score was set');
t.end();
});
}; };
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {

Loading…
Cancel
Save