Browse Source

feat(confidence): Add support for new query names

pull/1224/head
Julian Simioni 6 years ago
parent
commit
2a668612ed
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 7
      middleware/confidenceScoreFallback.js
  2. 76
      test/unit/middleware/confidenceScoreFallback.js

7
middleware/confidenceScoreFallback.js

@ -21,8 +21,11 @@ function computeScores(req, res, next) {
// do nothing if no result data set or if the query is not of the fallback variety
// later add disambiguation to this list
if (check.undefined(req.clean) || check.undefined(res) ||
check.undefined(res.data) || check.undefined(res.meta) ||
res.meta.query_type !== 'search_fallback') {
check.undefined(res.data) || check.undefined(res.meta)) {
return next();
}
if (['search_fallback', 'address_search_with_ids', 'structured'].includes(res.meta.queryType)) {
return next();
}

76
test/unit/middleware/confidenceScoreFallback.js

@ -137,6 +137,82 @@ module.exports.tests.confidenceScore = function(test, common) {
t.end();
});
test('placeholder style search queries should get confidence score', function(t) {
var req = {
clean: {
text: '123 Main St, City, NM',
parsed_text: {
number: 123,
street: 'Main St',
city: 'City',
state: 'NM'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
layer: 'address',
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: ['country1'],
region: ['region1'],
county: ['city1']
}
}],
meta: {
scores: [10],
query_type: 'address_search_with_ids'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 1.0, 'max score was set');
t.equal(res.data[0].match_type, 'exact', 'exact match indicated');
t.end();
});
test('structured search queries should get confidence score', function(t) {
var req = {
clean: {
text: '123 Main St, City, NM',
parsed_text: {
number: 123,
street: 'Main St',
city: 'City',
state: 'NM'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
layer: 'address',
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: ['country1'],
region: ['region1'],
county: ['city1']
}
}],
meta: {
scores: [10],
query_type: 'structured'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 1.0, 'max score was set');
t.equal(res.data[0].match_type, 'exact', 'exact match indicated');
t.end();
});
test('no fallback street query should have max score', function(t) {
var req = {
clean: {

Loading…
Cancel
Save