Browse Source

Merge pull request #666 from pelias/only-allow-queries-with-addresses

limited fallbackQuery usage to analysis with `street`
pull/625/head
Stephen K Hess 8 years ago committed by GitHub
parent
commit
e1e95f0945
  1. 19
      query/search.js
  2. 96
      test/unit/query/search.js

19
query/search.js

@ -120,25 +120,18 @@ function generateQuery( clean ){
} }
function getQuery(vs) { function getQuery(vs) {
if (isSingleFieldGeoambiguity(vs) && !hasQueryOrAddress(vs)) { if (hasStreet(vs)) {
// return `undefined` for now until we exorcise the geodisambiguation demons
return;
} else {
return fallbackQuery.render(vs); return fallbackQuery.render(vs);
} }
} // returning undefined is a signal to a later step that the addressit-parsed
// query should be queried for
return undefined;
function isSingleFieldGeoambiguity(vs) {
return ['neighbourhood', 'borough', 'locality', 'county', 'region', 'country'].filter(function(layer) {
return vs.isset('input:' + layer);
}).length === 1;
} }
function hasQueryOrAddress(vs) { function hasStreet(vs) {
return ['housenumber', 'street', 'query', 'category'].filter(function(layer) { return vs.isset('input:street');
return vs.isset('input:' + layer);
}).length > 0;
} }
module.exports = generateQuery; module.exports = generateQuery;

96
test/unit/query/search.js

@ -12,15 +12,21 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.query = function(test, common) { module.exports.tests.query = function(test, common) {
test('valid search + focus + bbox', function(t) { test('valid search + focus + bbox', function(t) {
var query = generate({ var clean = {
text: 'test', querySize: 10, parsed_text: {
street: 'street value'
},
text: 'test',
querySize: 10,
'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622, 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
'boundary.rect.min_lat': 47.47, 'boundary.rect.min_lat': 47.47,
'boundary.rect.max_lon': -61.84, 'boundary.rect.max_lon': -61.84,
'boundary.rect.max_lat': 11.51, 'boundary.rect.max_lat': 11.51,
'boundary.rect.min_lon': -103.16, 'boundary.rect.min_lon': -103.16,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox'); var expected = require('../fixture/search_linguistic_focus_bbox');
@ -30,14 +36,20 @@ module.exports.tests.query = function(test, common) {
}); });
test('valid search + bbox', function(t) { test('valid search + bbox', function(t) {
var query = generate({ var clean = {
text: 'test', querySize: 10, parsed_text: {
street: 'street value'
},
text: 'test',
querySize: 10,
'boundary.rect.min_lat': 47.47, 'boundary.rect.min_lat': 47.47,
'boundary.rect.max_lon': -61.84, 'boundary.rect.max_lon': -61.84,
'boundary.rect.max_lat': 11.51, 'boundary.rect.max_lat': 11.51,
'boundary.rect.min_lon': -103.16, 'boundary.rect.min_lon': -103.16,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox'); var expected = require('../fixture/search_linguistic_bbox');
@ -47,10 +59,15 @@ module.exports.tests.query = function(test, common) {
}); });
test('valid lingustic-only search', function(t) { test('valid lingustic-only search', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only'); var expected = require('../fixture/search_linguistic_only');
@ -60,11 +77,16 @@ module.exports.tests.query = function(test, common) {
}); });
test('search search + focus', function(t) { test('search search + focus', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622, 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus'); var expected = require('../fixture/search_linguistic_focus');
@ -74,14 +96,19 @@ module.exports.tests.query = function(test, common) {
}); });
test('search search + viewport', function(t) { test('search search + viewport', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
'focus.viewport.min_lat': 28.49136, 'focus.viewport.min_lat': 28.49136,
'focus.viewport.max_lat': 30.49136, 'focus.viewport.max_lat': 30.49136,
'focus.viewport.min_lon': -87.50622, 'focus.viewport.min_lon': -87.50622,
'focus.viewport.max_lon': -77.50622, 'focus.viewport.max_lon': -77.50622,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_viewport'); var expected = require('../fixture/search_linguistic_viewport');
@ -93,14 +120,19 @@ module.exports.tests.query = function(test, common) {
// viewport scale sizing currently disabled. // viewport scale sizing currently disabled.
// ref: https://github.com/pelias/api/pull/388 // ref: https://github.com/pelias/api/pull/388
test('search with viewport diagonal < 1km should set scale to 1km', function(t) { test('search with viewport diagonal < 1km should set scale to 1km', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
'focus.viewport.min_lat': 28.49135, 'focus.viewport.min_lat': 28.49135,
'focus.viewport.max_lat': 28.49137, 'focus.viewport.max_lat': 28.49137,
'focus.viewport.min_lon': -87.50622, 'focus.viewport.min_lon': -87.50622,
'focus.viewport.max_lon': -87.50624, 'focus.viewport.max_lon': -87.50624,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_viewport_min_diagonal'); var expected = require('../fixture/search_linguistic_viewport_min_diagonal');
@ -110,11 +142,16 @@ module.exports.tests.query = function(test, common) {
}); });
test('search search + focus on null island', function(t) { test('search search + focus on null island', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
'focus.point.lat': 0, 'focus.point.lon': 0, 'focus.point.lat': 0, 'focus.point.lon': 0,
layers: ['test'] layers: ['test']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_null_island'); var expected = require('../fixture/search_linguistic_focus_null_island');
@ -169,11 +206,16 @@ module.exports.tests.query = function(test, common) {
}); });
test('valid boundary.country search', function(t) { test('valid boundary.country search', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
text: 'test', querySize: 10, text: 'test', querySize: 10,
layers: ['test'], layers: ['test'],
'boundary.country': 'ABC' 'boundary.country': 'ABC'
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_boundary_country'); var expected = require('../fixture/search_boundary_country');
@ -183,10 +225,15 @@ module.exports.tests.query = function(test, common) {
}); });
test('valid sources filter', function(t) { test('valid sources filter', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
'text': 'test', 'text': 'test',
'sources': ['test_source'] 'sources': ['test_source']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_source_filtering'); var expected = require('../fixture/search_with_source_filtering');
@ -196,10 +243,15 @@ module.exports.tests.query = function(test, common) {
}); });
test('categories filter', function(t) { test('categories filter', function(t) {
var query = generate({ var clean = {
parsed_text: {
street: 'street value'
},
'text': 'test', 'text': 'test',
'categories': ['retail','food'] 'categories': ['retail','food']
}); };
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_category_filtering'); var expected = require('../fixture/search_with_category_filtering');

Loading…
Cancel
Save