Browse Source

added tests for new queries

left in place but commented out tests that will be supported when boundary, focus, and sources/layers issues are resolved.
pull/666/head
Stephen Hess 9 years ago
parent
commit
c257eb5fc3
  1. 371
      test/unit/fixture/search_fallback.js
  2. 199
      test/unit/fixture/search_geodisambiguation.js
  3. 335
      test/unit/query/search.js

371
test/unit/fixture/search_fallback.js

@ -0,0 +1,371 @@
module.exports = {
'query': {
'bool': {
'should': [
{
'bool': {
'_name': 'fallback.venue',
'must': [
{
'multi_match': {
'query': 'query value',
'type': 'phrase',
'fields': [
'phrase.default'
]
}
},
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.neighbourhood',
'parent.neighbourhood_a'
]
}
},
{
'multi_match': {
'query': 'borough value',
'type': 'phrase',
'fields': [
'parent.borough',
'parent.borough_a'
]
}
},
{
'multi_match': {
'query': 'city value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a',
'parent.localadmin',
'parent.localadmin_a'
]
}
},
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'venue'
}
}
}
},
{
'bool': {
'_name': 'fallback.address',
'must': [
{
'match_phrase': {
'address_parts.number': 'number value'
}
},
{
'match_phrase': {
'address_parts.street': 'street value'
}
},
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.neighbourhood',
'parent.neighbourhood_a'
]
}
},
{
'multi_match': {
'query': 'borough value',
'type': 'phrase',
'fields': [
'parent.borough',
'parent.borough_a'
]
}
},
{
'multi_match': {
'query': 'city value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a',
'parent.localadmin',
'parent.localadmin_a'
]
}
},
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'address'
}
}
}
},
{
'bool': {
'_name': 'fallback.neighbourhood',
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.neighbourhood',
'parent.neighbourhood_a'
]
}
},
{
'multi_match': {
'query': 'borough value',
'type': 'phrase',
'fields': [
'parent.borough',
'parent.borough_a'
]
}
},
{
'multi_match': {
'query': 'city value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a',
'parent.localadmin',
'parent.localadmin_a'
]
}
},
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'neighbourhood'
}
}
}
},
{
'bool': {
'_name': 'fallback.borough',
'must': [
{
'multi_match': {
'query': 'borough value',
'type': 'phrase',
'fields': [
'parent.borough',
'parent.borough_a'
]
}
},
{
'multi_match': {
'query': 'city value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a',
'parent.localadmin',
'parent.localadmin_a'
]
}
},
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'borough'
}
}
}
},
{
'bool': {
'_name': 'fallback.locality',
'must': [
{
'multi_match': {
'query': 'city value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a'
]
}
},
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'locality'
}
}
}
},
{
'bool': {
'_name': 'fallback.region',
'must': [
{
'multi_match': {
'query': 'state value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
},
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'region'
}
}
}
},
{
'bool': {
'_name': 'fallback.country',
'must': [
{
'multi_match': {
'query': 'country value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'country'
}
}
}
}
]
}
},
'size': 20,
'track_scores': true
};

199
test/unit/fixture/search_geodisambiguation.js

@ -0,0 +1,199 @@
module.exports = {
'query': {
'bool': {
'should': [
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.neighbourhood',
'parent.neighbourhood_a'
]
}
}
],
'filter': {
'term': {
'layer': 'neighbourhood'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.borough',
'parent.borough_a'
]
}
}
],
'filter': {
'term': {
'layer': 'borough'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.locality',
'parent.locality_a'
]
}
}
],
'filter': {
'term': {
'layer': 'locality'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.localadmin',
'parent.localadmin_a'
]
}
}
],
'filter': {
'term': {
'layer': 'localadmin'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.county',
'parent.county_a'
]
}
}
],
'filter': {
'term': {
'layer': 'county'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.macrocounty',
'parent.macrocounty_a'
]
}
}
],
'filter': {
'term': {
'layer': 'macrocounty'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.region',
'parent.region_a'
]
}
}
],
'filter': {
'term': {
'layer': 'region'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.macroregion',
'parent.macroregion_a'
]
}
}
],
'filter': {
'term': {
'layer': 'macroregion'
}
}
}
},
{
'bool': {
'must': [
{
'multi_match': {
'query': 'neighbourhood value',
'type': 'phrase',
'fields': [
'parent.country',
'parent.country_a'
]
}
}
],
'filter': {
'term': {
'layer': 'country'
}
}
}
}
]
}
},
'size': 20,
'track_scores': true
};

335
test/unit/query/search.js

@ -10,178 +10,201 @@ module.exports.tests.interface = function(test, common) {
};
module.exports.tests.query = function(test, common) {
test('valid search + focus + bbox', function(t) {
var query = generate({
text: 'test', querySize: 10,
'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
'boundary.rect.min_lat': 47.47,
'boundary.rect.max_lon': -61.84,
'boundary.rect.max_lat': 11.51,
'boundary.rect.min_lon': -103.16,
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox');
t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox');
t.end();
});
test('valid search + bbox', function(t) {
var query = generate({
text: 'test', querySize: 10,
'boundary.rect.min_lat': 47.47,
'boundary.rect.max_lon': -61.84,
'boundary.rect.max_lat': 11.51,
'boundary.rect.min_lon': -103.16,
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox');
t.deepEqual(compiled, expected, 'search_linguistic_bbox');
t.end();
});
test('valid lingustic-only search', function(t) {
var query = generate({
text: 'test', querySize: 10,
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only');
t.deepEqual(compiled, expected, 'search_linguistic_only');
t.end();
});
// test('valid search + focus + bbox', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
// 'boundary.rect.min_lat': 47.47,
// 'boundary.rect.max_lon': -61.84,
// 'boundary.rect.max_lat': 11.51,
// 'boundary.rect.min_lon': -103.16,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_focus_bbox');
//
// t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox');
// t.end();
// });
// test('valid search + bbox', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'boundary.rect.min_lat': 47.47,
// 'boundary.rect.max_lon': -61.84,
// 'boundary.rect.max_lat': 11.51,
// 'boundary.rect.min_lon': -103.16,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_bbox');
//
// t.deepEqual(compiled, expected, 'search_linguistic_bbox');
// t.end();
// });
// test('valid lingustic-only search', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_only');
//
// t.deepEqual(compiled, expected, 'search_linguistic_only');
// t.end();
// });
// test('search search + focus', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_focus');
//
// t.deepEqual(compiled, expected, 'search_linguistic_focus');
// t.end();
// });
// test('search search + viewport', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'focus.viewport.min_lat': 28.49136,
// 'focus.viewport.max_lat': 30.49136,
// 'focus.viewport.min_lon': -87.50622,
// 'focus.viewport.max_lon': -77.50622,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_viewport');
//
// t.deepEqual(compiled, expected, 'search_linguistic_viewport');
// t.end();
// });
// viewport scale sizing currently disabled.
// ref: https://github.com/pelias/api/pull/388
// test('search with viewport diagonal < 1km should set scale to 1km', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'focus.viewport.min_lat': 28.49135,
// 'focus.viewport.max_lat': 28.49137,
// 'focus.viewport.min_lon': -87.50622,
// 'focus.viewport.max_lon': -87.50624,
// layers: ['test']
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_linguistic_viewport_min_diagonal');
//
// t.deepEqual(compiled, expected, 'valid search query');
// t.end();
// });
// test('search search + focus on null island', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// 'focus.point.lat': 0, 'focus.point.lon': 0,
// layers: ['test']
// });
//
// 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.end();
// });
test('parsed_text with all fields should use FallbackQuery', function(t) {
var clean = {
parsed_text: {
query: 'query value',
category: 'category value',
number: 'number value',
street: 'street value',
neighbourhood: 'neighbourhood value',
borough: 'borough value',
postalcode: 'postalcode value',
city: 'city value',
county: 'county value',
state: 'state value',
country: 'country value'
}
};
test('search search + focus', function(t) {
var query = generate({
text: 'test', querySize: 10,
'focus.point.lat': 29.49136, 'focus.point.lon': -82.50622,
layers: ['test']
});
var query = generate(clean);
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus');
var compiled = JSON.parse(JSON.stringify(query));
var expected = require('../fixture/search_fallback');
t.deepEqual(compiled, expected, 'search_linguistic_focus');
t.deepEqual(compiled, expected, 'fallbackQuery');
t.end();
});
test('search search + focus on null island', function(t) {
var query = generate({
text: 'test', querySize: 10,
'focus.point.lat': 0, 'focus.point.lon': 0,
layers: ['test']
});
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.end();
});
test('valid query with a full valid address', function(t) {
var query = generate({ text: '123 main st new york ny 10010 US',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
test('parsed_text with single admin field should use GeodisambiguationQuery', function(t) {
var clean = {
parsed_text: {
number: '123',
street: 'main st',
state: 'NY',
country: 'USA',
postalcode: '10010',
regions: [ 'new york' ]
neighbourhood: 'neighbourhood value'
}
});
};
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address');
var query = generate(clean);
t.deepEqual(compiled, expected, 'search_full_address');
t.end();
});
var compiled = JSON.parse(JSON.stringify(query));
var expected = require('../fixture/search_geodisambiguation');
test('valid query with partial address', function(t) {
var query = generate({ text: 'soho grand, new york',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: { name: 'soho grand',
state: 'NY',
regions: [ 'soho grand' ],
admin_parts: 'new york'
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_partial_address');
t.deepEqual(compiled, expected, 'search_partial_address');
t.end();
});
test('valid query with regions in address', function(t) {
var query = generate({ text: '1 water st manhattan ny',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: { number: '1',
street: 'water st',
state: 'NY',
regions: [ 'manhattan' ]
},
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_regions_address');
t.deepEqual(compiled, expected, 'search_regions_address');
t.deepEqual(compiled, expected, 'geodisambiguationQuery');
t.end();
});
test('valid boundary.country search', function(t) {
var query = generate({
text: 'test', querySize: 10,
layers: ['test'],
'boundary.country': 'ABC'
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_boundary_country');
t.deepEqual(compiled, expected, 'search: valid boundary.country query');
t.end();
});
test('valid sources filter', function(t) {
var query = generate({
'text': 'test',
'sources': ['test_source']
});
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.end();
});
test('categories filter', function(t) {
var query = generate({
'text': 'test',
'categories': ['retail','food']
});
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.end();
});
// test('valid boundary.country search', function(t) {
// var query = generate({
// text: 'test', querySize: 10,
// layers: ['test'],
// 'boundary.country': 'ABC'
// });
//
// var compiled = JSON.parse( JSON.stringify( query ) );
// var expected = require('../fixture/search_boundary_country');
//
// t.deepEqual(compiled, expected, 'search: valid boundary.country query');
// t.end();
// });
// test('valid sources filter', function(t) {
// var query = generate({
// 'text': 'test',
// 'sources': ['test_source']
// });
//
// 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.end();
// });
//test('categories filter', function(t) {
//var query = generate({
//'text': 'test',
//'categories': ['retail','food']
//});
//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.end();
//});
};
module.exports.all = function (tape, common) {

Loading…
Cancel
Save