Skip to content

Commit

Permalink
only query ES for non-coarse layers on non-coarse reverse requests
Browse files Browse the repository at this point in the history
  • Loading branch information
trescube committed Jun 6, 2017
1 parent 1c9c68e commit 10b1d28
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 7 deletions.
4 changes: 3 additions & 1 deletion query/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const peliasQuery = require('pelias-query');
const defaults = require('./reverse_defaults');
const check = require('check-types');
const _ = require('lodash');
const logger = require('pelias-logger').get('api');

//------------------------------
Expand Down Expand Up @@ -44,7 +45,8 @@ function generateQuery( clean ){

// layers
if( check.array(clean.layers) && clean.layers.length ) {
vs.var( 'layers', clean.layers);
// only include non-coarse layers
vs.var( 'layers', _.intersection(clean.layers, ['address', 'street', 'venue']));
logStr += '[param:layers] ';
}

Expand Down
1 change: 1 addition & 0 deletions query/reverse_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {

'size': 1,
'track_scores': true,
'layers': ['venue', 'address', 'street'],

'centroid:field': 'center_point',

Expand Down
5 changes: 5 additions & 0 deletions test/unit/fixture/reverse_null_island.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = {
'lon': 0
}
}
},
{
'terms': {
'layer': ['venue', 'address', 'street']
}
}]
}
},
Expand Down
5 changes: 5 additions & 0 deletions test/unit/fixture/reverse_standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = {
'lon': -82.50622
}
}
},
{
'terms': {
'layer': ['venue', 'address', 'street']
}
}]
}
},
Expand Down
5 changes: 5 additions & 0 deletions test/unit/fixture/reverse_with_boundary_country.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module.exports = {
'lon': -82.50622
}
}
},
{
'terms': {
'layer': ['venue', 'address', 'street']
}
}]
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/reverse_with_layer_filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
},
{
'terms': {
'layer': ['country']
'layer': ['venue', 'address', 'street']
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var vs = require('../../../query/reverse_defaults');

module.exports = {
'query': {
'bool': {
'filter': [
{
'geo_distance': {
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
}
},
{
'terms': {
'layer': ['venue', 'street']
}
}
]
}
},
'sort': [
'_score',
{
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
'order': 'asc',
'distance_type': 'plane'
}
}
],
'size': vs.size,
'track_scores': true
};
5 changes: 5 additions & 0 deletions test/unit/fixture/reverse_with_source_filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module.exports = {
'terms': {
'source': ['test']
}
},
{
'terms': {
'layer': ['venue', 'address', 'street']
}
}
]
}
Expand Down
33 changes: 28 additions & 5 deletions test/unit/query/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,46 @@ module.exports.tests.query = function(test, common) {
t.end();
});

test('valid layers filter', function(t) {
var query = generate({
test('valid layers filter', (t) => {
const query = generate({
'point.lat': 29.49136,
'point.lon': -82.50622,
'boundary.circle.lat': 29.49136,
'boundary.circle.lon': -82.50622,
'boundary.circle.radius': 500,
'layers': ['country']
// only venue, address, and street layers should be retained
'layers': ['neighbourhood', 'venue', 'locality', 'address', 'region', 'street', 'country']
});

var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_with_layer_filtering');
const compiled = JSON.parse( JSON.stringify( query ) );
const expected = require('../fixture/reverse_with_layer_filtering');

t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering');
t.end();

});

test('valid layers filter - subset of non-coarse layers', (t) => {
const query = generate({
'point.lat': 29.49136,
'point.lon': -82.50622,
'boundary.circle.lat': 29.49136,
'boundary.circle.lon': -82.50622,
'boundary.circle.radius': 500,
// only venue, address, and street layers should be retained
'layers': ['neighbourhood', 'venue', 'street', 'locality']
});

const compiled = JSON.parse( JSON.stringify( query ) );
const expected = require('../fixture/reverse_with_layer_filtering_non_coarse_subset');

t.deepEqual(compiled.type, 'reverse', 'query type set');
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering');
t.end();

});

};

module.exports.all = function (tape, common) {
Expand Down

0 comments on commit 10b1d28

Please sign in to comment.