Browse Source

Merge pull request #674 from pelias/confidence-score-fix

Confidence score fix
pull/625/head
Stephen K Hess 8 years ago committed by GitHub
parent
commit
d53026d6e6
  1. 10
      controller/search.js
  2. 1
      helper/geojsonify_place_details.js
  3. 5
      middleware/confidenceScore.js
  4. 118
      middleware/confidenceScoreFallback.js
  5. 4
      middleware/geocodeJSON.js
  6. 5
      query/autocomplete.js
  7. 5
      query/reverse.js
  8. 5
      query/search.js
  9. 6
      query/search_original.js
  10. 2
      routes/v1.js
  11. 3
      test/ciao/search/address_parsing.coffee
  12. 80
      test/ciao_test_data.js
  13. 7
      test/unit/controller/search.js
  14. 49
      test/unit/middleware/confidenceScore.js
  15. 250
      test/unit/middleware/confidenceScoreFallback.js
  16. 5
      test/unit/mock/query.js
  17. 31
      test/unit/query/autocomplete.js
  18. 23
      test/unit/query/reverse.js
  19. 33
      test/unit/query/search.js
  20. 35
      test/unit/query/search_original.js
  21. 1
      test/unit/run.js

10
controller/search.js

@ -31,10 +31,10 @@ function setup( config, backend, query ){
// log clean parameters for stats
logger.info('[req]', 'endpoint=' + req.path, cleanOutput);
var query_body = query(req.clean);
var renderedQuery = query(req.clean);
// if there's no query to call ES with, skip the service
if (_.isUndefined(query_body)) {
if (_.isUndefined(renderedQuery)) {
return next();
}
@ -42,7 +42,7 @@ function setup( config, backend, query ){
var cmd = {
index: config.indexName,
searchType: 'dfs_query_then_fetch',
body: query_body
body: renderedQuery.body
};
logger.debug( '[ES req]', cmd );
@ -61,7 +61,9 @@ function setup( config, backend, query ){
// set response data
else {
res.data = docs;
res.meta = meta;
res.meta = meta || {};
// store the query_type for subsequent middleware
res.meta.query_type = renderedQuery.type;
}
logger.debug('[ES response]', docs);
next();

1
helper/geojsonify_place_details.js

@ -8,6 +8,7 @@ var DETAILS_PROPS = [
{ name: 'street', type: 'string' },
{ name: 'postalcode', type: 'string' },
{ name: 'confidence', type: 'default' },
{ name: 'match_type', type: 'string' },
{ name: 'distance', type: 'default' },
{ name: 'country', type: 'string' },
{ name: 'country_gid', type: 'string' },

5
middleware/confidenceScore.js

@ -25,9 +25,10 @@ function setup(peliasConfig) {
}
function computeScores(req, res, next) {
// do nothing if no result data set
// do nothing if no result data set or if query is not of the original variety
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') {
return next();
}

118
middleware/confidenceScoreFallback.js

@ -0,0 +1,118 @@
/**
*
* Basic confidence score should be computed and returned for each item in the results.
* The score should range between 0-1, and take into consideration as many factors as possible.
*
* Some factors to consider:
*
* - number of results from ES
* - fallback status (aka layer match between expected and actual)
*/
var check = require('check-types');
var logger = require('pelias-logger').get('api-confidence');
function setup() {
return computeScores;
}
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 !== 'fallback') {
return next();
}
// loop through data items and determine confidence scores
res.data = res.data.map(computeConfidenceScore.bind(null, req));
next();
}
/**
* Check all types of things to determine how confident we are that this result
* is correct.
*
* @param {object} req
* @param {object} hit
* @returns {object}
*/
function computeConfidenceScore(req, hit) {
// if parsed text doesn't exist, which it never should, just assign a low confidence and move on
if (!req.clean.hasOwnProperty('parsed_text')) {
hit.confidence = 0.1;
hit.match_type = 'unknown';
return hit;
}
// start with a confidence level of 1 because we trust ES queries to be accurate
hit.confidence = 1.0;
// in the case of fallback there might be deductions
hit.confidence *= checkFallbackLevel(req, hit);
// truncate the precision
hit.confidence = Number((hit.confidence).toFixed(3));
return hit;
}
function checkFallbackLevel(req, hit) {
if (checkFallbackOccurred(req, hit)) {
hit.match_type = 'fallback';
// if we know a fallback occurred, deduct points based on layer granularity
switch (hit.layer) {
case 'venue':
case 'address':
logger.warn('Fallback scenarios should not result in address or venue records!', req.clean.parsed_text);
return 0.8;
case 'street':
return 0.8;
case 'locality':
case 'borough':
case 'neighbourhood':
return 0.6;
case 'macrocounty':
case 'county':
case 'localadmin':
return 0.4;
case 'region':
return 0.3;
case 'country':
case 'dependency':
case 'macroregion':
return 0.1;
default:
return 0.1;
}
}
hit.match_type = 'exact';
return 1.0;
}
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') ||
(requestedStreet(req) && hit.layer !== 'street');
}
function requestedAddress(req) {
// house number and street name were specified
return req.clean.parsed_text.hasOwnProperty('number') &&
req.clean.parsed_text.hasOwnProperty('street');
}
function requestedStreet(req) {
// only street name was specified
return !req.clean.parsed_text.hasOwnProperty('number') &&
req.clean.parsed_text.hasOwnProperty('street');
}
module.exports = setup;

4
middleware/geocodeJSON.js

@ -1,6 +1,7 @@
var url = require('url');
var extend = require('extend');
var geojsonify = require('../helper/geojsonify');
var _ = require('lodash');
/**
* Returns a middleware function that converts elasticsearch
@ -79,7 +80,8 @@ function convertToGeocodeJSON(req, res, next, opts) {
function addMessages(req, msgType, geocoding) {
if (req.hasOwnProperty(msgType) && req[msgType].length) {
geocoding[msgType] = req[msgType];
// cleanup arrays to make sure there are no duplicates
geocoding[msgType] = _.uniq(req[msgType]);
}
}

5
query/autocomplete.js

@ -114,7 +114,10 @@ function generateQuery( clean ){
textParser( clean.parsed_text, vs );
}
return query.render( vs );
return {
type: 'autocomplete',
body: query.render(vs)
};
}
module.exports = generateQuery;

5
query/reverse.js

@ -71,7 +71,10 @@ function generateQuery( clean ){
vs.var('input:categories', clean.categories);
}
return query.render( vs );
return {
type: 'reverse',
body: query.render(vs)
};
}
module.exports = generateQuery;

5
query/search.js

@ -121,7 +121,10 @@ function generateQuery( clean ){
function getQuery(vs) {
if (hasStreet(vs)) {
return fallbackQuery.render(vs);
return {
type: 'fallback',
body: fallbackQuery.render(vs)
};
}
// returning undefined is a signal to a later step that the addressit-parsed

6
query/search_original.js

@ -125,7 +125,11 @@ function generateQuery( clean ){
textParser( clean.parsed_text, vs );
}
return query.render( vs );
return {
type: 'original',
body: query.render(vs)
};
}
module.exports = generateQuery;

2
routes/v1.js

@ -37,6 +37,7 @@ var postProc = {
trimByGranularity: require('../middleware/trimByGranularity'),
distances: require('../middleware/distance'),
confidenceScores: require('../middleware/confidenceScore'),
confidenceScoresFallback: require('../middleware/confidenceScoreFallback'),
confidenceScoresReverse: require('../middleware/confidenceScoreReverse'),
dedupe: require('../middleware/dedupe'),
localNamingConventions: require('../middleware/localNamingConventions'),
@ -78,6 +79,7 @@ function addRoutes(app, peliasConfig) {
postProc.trimByGranularity(),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
postProc.confidenceScoresFallback(),
postProc.dedupe(),
postProc.localNamingConventions(),
postProc.renamePlacenames(),

3
test/ciao/search/address_parsing.coffee

@ -39,3 +39,6 @@ json.geocoding.query.parsed_text['street'].should.eql 'w 26th st'
json.geocoding.query.parsed_text['state'].should.eql 'NY'
json.geocoding.query.parsed_text['regions'].should.eql []
json.geocoding.query.parsed_text['admin_parts'].should.eql "ny"
json.features[0].properties.confidence.should.eql 1
json.features[0].properties.match_type.should.eql "exact"

80
test/ciao_test_data.js

@ -48,6 +48,86 @@ types.forEach( function( type, i1 ){
});
});
client.index(
{
index: config.indexName,
type: 'address',
id: 'way:265038872',
body: {
'center_point': {
'lon': -73.990425,
'lat': 40.744131
},
'parent': {
'country': [
'United States'
],
'neighbourhood_id': [
'85869245'
],
'country_a': [
'USA'
],
'locality_a': [
null
],
'region_id': [
'85688543'
],
'county': [
'New York County'
],
'borough_a': [
null
],
'borough_id': [
'421205771'
],
'locality': [
'New York'
],
'borough': [
'Manhattan'
],
'region_a': [
'NY'
],
'county_id': [
'102081863'
],
'locality_id': [
'85977539'
],
'neighbourhood_a': [
null
],
'neighbourhood': [
'Flatiron District'
],
'region': [
'New York'
],
'country_id': [
'85633793'
],
'county_a': [
null
]
},
'name': {'default': '30 West 26th Street'},
'address_parts': {
'zip': '10010',
'number': '30',
'street': 'West 26th Street'
},
'alpha3': 'USA',
'source': 'openstreetmap',
'source_id': 'way:265038872',
'layer': 'address'
}
}
);
// call refresh so the index merges the changes
actions.push( function( done ){
client.indices.refresh( { index: config.indexName }, done);

7
test/unit/controller/search.js

@ -47,7 +47,8 @@ module.exports.tests.functional_success = function(test, common) {
}];
var expectedMeta = {
scores: [10, 20]
scores: [10, 20],
query_type: 'mock'
};
var expectedData = [
@ -197,9 +198,7 @@ module.exports.tests.existing_results = function(test, common) {
module.exports.tests.undefined_query = function(test, common) {
test('query returning undefined should not call service', function(t) {
// a function that returns undefined
var query = function() {
return;
};
var query = function () { return; };
var search_service_was_called = false;

49
test/unit/middleware/confidenceScore.js

@ -46,7 +46,8 @@ module.exports.tests.confidenceScore = function(test, common) {
}
}],
meta: {
scores: [10]
scores: [10],
query_type: 'original'
}
};
@ -86,7 +87,10 @@ module.exports.tests.confidenceScore = function(test, common) {
county: ['city2']
}
}],
meta: {scores: [10]}
meta: {
scores: [10],
query_type: 'original'
}
};
confidenceScore(req, res, function() {});
@ -119,13 +123,52 @@ module.exports.tests.confidenceScore = function(test, common) {
county: ['city1']
}
}],
meta: {scores: [10]}
meta: {
scores: [10],
query_type: 'original'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.28, 'score was set');
t.end();
});
test('should only work for original query_type', 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,
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],
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.false(res.data[0].hasOwnProperty('confidence'), 'score was not set');
t.end();
});
};
module.exports.all = function (tape, common) {

250
test/unit/middleware/confidenceScoreFallback.js

@ -0,0 +1,250 @@
var confidenceScore = require('../../../middleware/confidenceScoreFallback')();
module.exports.tests = {};
module.exports.tests.confidenceScore = function(test, common) {
test('empty res and req should not throw exception', function(t) {
function testIt() {
confidenceScore({}, {}, function() {});
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
});
test('res.results without parsed_text should not throw exception', function(t) {
var req = {};
var res = {
data: [{
name: 'foo'
}],
meta: [10]
};
function testIt() {
confidenceScore(req, res, function() {});
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
});
test('hit without address should not error', function(t) {
var req = {
clean: {
text: 'test name3',
parsed_text: {
postalcode: 12345
}
}
};
var res = {
data: [{
name: {
default: 'foo'
}
}],
meta: {
scores: [10],
query_type: 'original'
}
};
function testIt() {
confidenceScore(req, res, function() {});
}
t.doesNotThrow(testIt, 'an exception should not have been thrown with no address');
t.end();
});
test('res.results without parsed_text should not throw exception', function(t) {
var req = {
clean: { text: 'test name1' }
};
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: ['state1'],
county: ['city1']
}
}, {
_score: 20,
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
parent: {
country: ['country2'],
region: ['state2'],
county: ['city2']
}
}],
meta: {
scores: [10],
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.1, 'score was set');
t.end();
});
test('no fallback addresses should have max score', 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: '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: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 1.0, 'max score was set');
t.end();
});
test('no fallback street query should have max score', function(t) {
var req = {
clean: {
text: 'Main St, City, NM',
parsed_text: {
street: 'Main St',
state: 'NM'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
layer: 'street',
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: ['country1'],
region: ['region1'],
county: ['city1']
}
}],
meta: {
scores: [10],
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 1.0, 'max score was set');
t.end();
});
test('fallback to locality 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: 'locality',
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: {
text: '123 Main St, City, NM, USA',
parsed_text: {
number: 123,
street: 'Main St',
state: 'NM',
country: 'USA'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
layer: 'country',
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.1, 'score was set');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('[middleware] confidenceScore: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

5
test/unit/mock/query.js

@ -4,7 +4,10 @@ function setup(){
}
function query( clean ){
return clean;
return {
type: 'mock',
body: clean
};
}
module.exports = setup;

31
test/unit/query/autocomplete.js

@ -1,4 +1,3 @@
var generate = require('../../../query/autocomplete');
module.exports.tests = {};
@ -22,7 +21,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_only');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_only');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_only');
t.end();
});
@ -37,7 +37,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_multiple_tokens');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_multiple_tokens');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_multiple_tokens');
t.end();
});
@ -57,7 +58,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_with_admin');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_with_admin');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_with_admin');
t.end();
});
@ -75,7 +77,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_final_token');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_final_token');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_final_token');
t.end();
});
@ -92,7 +95,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_focus');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_focus');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus');
t.end();
});
@ -109,7 +113,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_focus_null_island');
t.deepEqual(compiled, expected, 'autocomplete_linguistic_focus_null_island');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus_null_island');
t.end();
});
@ -125,7 +130,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_with_source_filtering');
t.deepEqual(compiled, expected, 'valid autocomplete query with source filtering');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'valid autocomplete query with source filtering');
t.end();
});
@ -141,7 +147,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_with_layer_filtering');
t.deepEqual(compiled, expected, 'valid autocomplete query with layer filtering');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'valid autocomplete query with layer filtering');
t.end();
});
@ -161,7 +168,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_single_character_street');
t.deepEqual(compiled, expected, 'autocomplete_single_character_street');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_single_character_street');
t.end();
});
@ -177,7 +185,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_boundary_country');
t.deepEqual(compiled, expected, 'autocomplete: valid boundary.country query');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.country query');
t.end();
});
};

23
test/unit/query/reverse.js

@ -22,7 +22,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_standard');
t.deepEqual(compiled, expected, 'reverse_standard');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'reverse_standard');
t.end();
});
@ -38,7 +39,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_null_island');
t.deepEqual(compiled, expected, 'reverse_null_island');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'reverse_null_island');
t.end();
});
@ -54,7 +56,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = '123km';
t.deepEqual(compiled.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius');
t.end();
});
@ -71,8 +74,9 @@ module.exports.tests.query = function(test, common) {
// this should not equal `point.lat` and `point.lon` as it was explitely specified
var expected = { lat: clean['boundary.circle.lat'], lon: clean['boundary.circle.lon'] };
var centroid = compiled.query.bool.filter[0].geo_distance.center_point;
var centroid = compiled.body.query.bool.filter[0].geo_distance.center_point;
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(centroid, expected, 'reverse: boundary.circle/lon overrides point.lat/lon');
t.end();
});
@ -87,7 +91,7 @@ module.exports.tests.query = function(test, common) {
});
var compiled = JSON.parse( JSON.stringify( query ) );
t.equal( compiled.size, expected[index], 'valid reverse query for size: '+ size);
t.equal( compiled.body.size, expected[index], 'valid reverse query for size: '+ size);
});
t.end();
});
@ -105,7 +109,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_with_boundary_country');
t.deepEqual(compiled, expected, 'valid reverse query with boundary.country');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'valid reverse query with boundary.country');
t.end();
});
@ -122,7 +127,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_with_source_filtering');
t.deepEqual(compiled, expected, 'valid reverse query with source filtering');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering');
t.end();
});
@ -139,7 +145,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_with_layer_filtering');
t.deepEqual(compiled, expected, 'valid reverse query with source filtering');
t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering');
t.end();
});
};

33
test/unit/query/search.js

@ -31,7 +31,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox');
t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox');
t.end();
});
@ -54,7 +55,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox');
t.deepEqual(compiled, expected, 'search_linguistic_bbox');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_bbox');
t.end();
});
@ -72,7 +74,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only');
t.deepEqual(compiled, expected, 'search_linguistic_only');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_only');
t.end();
});
@ -91,7 +94,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus');
t.deepEqual(compiled, expected, 'search_linguistic_focus');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus');
t.end();
});
@ -113,7 +117,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_viewport');
t.deepEqual(compiled, expected, 'search_linguistic_viewport');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_viewport');
t.end();
});
@ -137,7 +142,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_viewport_min_diagonal');
t.deepEqual(compiled, expected, 'valid search query');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'valid search query');
t.end();
});
@ -156,7 +162,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_null_island');
t.deepEqual(compiled, expected, 'search_linguistic_focus_null_island');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus_null_island');
t.end();
});
@ -182,7 +189,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse(JSON.stringify(query));
var expected = require('../fixture/search_fallback');
t.deepEqual(compiled, expected, 'fallbackQuery');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'fallbackQuery');
t.end();
});
@ -220,7 +228,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_boundary_country');
t.deepEqual(compiled, expected, 'search: valid boundary.country query');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search: valid boundary.country query');
t.end();
});
@ -238,7 +247,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_source_filtering');
t.deepEqual(compiled, expected, 'search: valid search query with source filtering');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'search: valid search query with source filtering');
t.end();
});
@ -256,7 +266,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_category_filtering');
t.deepEqual(compiled, expected, 'valid search query with category filtering');
t.deepEqual(compiled.type, 'fallback', 'query type set');
t.deepEqual(compiled.body, expected, 'valid search query with category filtering');
t.end();
});
};

35
test/unit/query/search_original.js

@ -24,7 +24,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox_original');
t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox');
t.end();
});
@ -41,7 +42,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox_original');
t.deepEqual(compiled, expected, 'search_linguistic_bbox');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_bbox');
t.end();
});
@ -54,7 +56,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only_original');
t.deepEqual(compiled, expected, 'search_linguistic_only');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_only');
t.end();
});
@ -68,7 +71,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_original');
t.deepEqual(compiled, expected, 'search_linguistic_focus');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus');
t.end();
});
@ -82,7 +86,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_null_island_original');
t.deepEqual(compiled, expected, 'search_linguistic_focus_null_island');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_linguistic_focus_null_island');
t.end();
});
@ -103,7 +108,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address_original');
t.deepEqual(compiled, expected, 'search_full_address');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_full_address');
t.end();
});
@ -121,7 +127,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_partial_address_original');
t.deepEqual(compiled, expected, 'search_partial_address');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_partial_address');
t.end();
});
@ -133,13 +140,14 @@ module.exports.tests.query = function(test, common) {
street: 'water st',
state: 'NY',
regions: [ 'manhattan' ]
},
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_regions_address_original');
t.deepEqual(compiled, expected, 'search_regions_address');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_regions_address');
t.end();
});
@ -153,7 +161,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_boundary_country_original');
t.deepEqual(compiled, expected, 'search: valid boundary.country query');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search: valid boundary.country query');
t.end();
});
@ -166,7 +175,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_source_filtering_original');
t.deepEqual(compiled, expected, 'search: valid search query with source filtering');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search: valid search query with source filtering');
t.end();
});
@ -179,7 +189,8 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_category_filtering_original');
t.deepEqual(compiled, expected, 'valid search query with category filtering');
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'valid search query with category filtering');
t.end();
});
};

1
test/unit/run.js

@ -26,6 +26,7 @@ var tests = [
require('./helper/sizeCalculator'),
require('./middleware/access_log'),
require('./middleware/confidenceScore'),
require('./middleware/confidenceScoreFallback'),
require('./middleware/confidenceScoreReverse'),
require('./middleware/distance'),
require('./middleware/localNamingConventions'),

Loading…
Cancel
Save