Browse Source

Merge pull request #1224 from pelias/fix-query-types

Fix confidence score detection
add-params-to-parser-logs
Julian Simioni 6 years ago committed by GitHub
parent
commit
50433d9848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      controller/placeholder.js
  2. 2
      middleware/confidenceScore.js
  3. 7
      middleware/confidenceScoreFallback.js
  4. 42
      test/unit/controller/placeholder.js
  5. 14
      test/unit/middleware/confidenceScore.js
  6. 106
      test/unit/middleware/confidenceScoreFallback.js

2
controller/placeholder.js

@ -250,7 +250,7 @@ function setup(placeholderService, do_geometric_filters_apply, should_execute) {
// boundary.country filter must happen after synthesis since multiple // boundary.country filter must happen after synthesis since multiple
// lineages may produce different country docs // lineages may produce different country docs
res.meta = { res.meta = {
query_type: 'fallback' query_type: 'search_fallback'
}; };
res.data = results res.data = results

2
middleware/confidenceScore.js

@ -29,7 +29,7 @@ function computeScores(req, res, next) {
// do nothing if no result data set or if query is not of the original variety // do nothing if no result data set or if query is not of the original variety
if (check.undefined(req.clean) || check.undefined(res) || if (check.undefined(req.clean) || check.undefined(res) ||
check.undefined(res.data) || check.undefined(res.meta) || check.undefined(res.data) || check.undefined(res.meta) ||
res.meta.query_type !== 'original') { res.meta.query_type !== 'search_original') {
return next(); return next();
} }

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 // do nothing if no result data set or if the query is not of the fallback variety
// later add disambiguation to this list // later add disambiguation to this list
if (check.undefined(req.clean) || check.undefined(res) || if (check.undefined(req.clean) || check.undefined(res) ||
check.undefined(res.data) || check.undefined(res.meta) || check.undefined(res.data) || check.undefined(res.meta)) {
res.meta.query_type !== 'fallback') { return next();
}
if (['search_fallback', 'address_search_with_ids', 'structured'].includes(res.meta.queryType)) {
return next(); return next();
} }

42
test/unit/controller/placeholder.js

@ -212,7 +212,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -330,7 +330,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -393,7 +393,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -453,7 +453,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -518,7 +518,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -583,7 +583,7 @@ module.exports.tests.success = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -756,7 +756,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -874,7 +874,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1075,7 +1075,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1191,7 +1191,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1345,7 +1345,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1480,7 +1480,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1629,7 +1629,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1779,7 +1779,7 @@ module.exports.tests.result_filtering = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1906,7 +1906,7 @@ module.exports.tests.lineage_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -1980,7 +1980,7 @@ module.exports.tests.lineage_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -2053,7 +2053,7 @@ module.exports.tests.lineage_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -2113,7 +2113,7 @@ module.exports.tests.geometry_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -2172,7 +2172,7 @@ module.exports.tests.centroid_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -2232,7 +2232,7 @@ module.exports.tests.centroid_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {
@ -2302,7 +2302,7 @@ module.exports.tests.boundingbox_errors = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
const expected_res = { const expected_res = {
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
}, },
data: [ data: [
{ {

14
test/unit/middleware/confidenceScore.js

@ -47,7 +47,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_original'
} }
}; };
@ -89,7 +89,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_original'
} }
}; };
@ -125,7 +125,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_original'
} }
}; };
@ -134,7 +134,7 @@ module.exports.tests.confidenceScore = function(test, common) {
t.end(); t.end();
}); });
test('should only work for original query_type', function(t) { test('should only work for search_original query_type', function(t) {
var req = { var req = {
clean: { clean: {
text: '123 Main St, City, NM', text: '123 Main St, City, NM',
@ -161,7 +161,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -191,7 +191,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_original'
} }
}; };
@ -223,7 +223,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_original'
} }
}; };

106
test/unit/middleware/confidenceScoreFallback.js

@ -47,7 +47,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'original' query_type: 'search_fallback'
} }
}; };
@ -89,7 +89,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -127,7 +127,83 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
}
};
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('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'
} }
}; };
@ -163,7 +239,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -197,7 +273,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -230,7 +306,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -265,7 +341,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -300,7 +376,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -336,7 +412,7 @@ module.exports.tests.confidenceScore = function(test, common) {
}], }],
meta: { meta: {
scores: [10], scores: [10],
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -360,7 +436,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'locality' layer: 'locality'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -384,7 +460,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'localadmin' layer: 'localadmin'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -408,7 +484,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'region' layer: 'region'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -433,7 +509,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'country' layer: 'country'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
@ -461,7 +537,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'postalcode' layer: 'postalcode'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
confidenceScore(req, res, function() {}); confidenceScore(req, res, function() {});
@ -485,7 +561,7 @@ module.exports.tests.confidenceScore = function(test, common) {
layer: 'postalcode' layer: 'postalcode'
}], }],
meta: { meta: {
query_type: 'fallback' query_type: 'search_fallback'
} }
}; };
confidenceScore(req, res, function() {}); confidenceScore(req, res, function() {});

Loading…
Cancel
Save