From 7d71e3210424182556e54284de51930fab5d43cd Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 24 Mar 2016 14:01:37 +0100 Subject: [PATCH 1/2] bugfix: enable support for ?sources= filtering on /reverse --- query/reverse.js | 1 + test/ciao/reverse/layers_alias_address.coffee | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/ciao/reverse/layers_alias_address.coffee diff --git a/query/reverse.js b/query/reverse.js index 856b9540..3e9c3aa5 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -15,6 +15,7 @@ query.sort( peliasQuery.view.sort_distance ); // non-scoring hard filters query.filter( peliasQuery.view.boundary_circle ); +query.filter( peliasQuery.view.sources ); // -------------------------------- diff --git a/test/ciao/reverse/layers_alias_address.coffee b/test/ciao/reverse/layers_alias_address.coffee new file mode 100644 index 00000000..fb8e3262 --- /dev/null +++ b/test/ciao/reverse/layers_alias_address.coffee @@ -0,0 +1,33 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=address' + +#? 200 ok +response.statusCode.should.be.equal 200 +response.should.have.header 'charset', 'utf8' +response.should.have.header 'content-type', 'application/json; charset=utf-8' + +#? valid geocoding block +should.exist json.geocoding +should.exist json.geocoding.version +should.exist json.geocoding.attribution +should.exist json.geocoding.query +should.exist json.geocoding.engine +should.exist json.geocoding.engine.name +should.exist json.geocoding.engine.author +should.exist json.geocoding.engine.version +should.exist json.geocoding.timestamp + +#? valid geojson +json.type.should.be.equal 'FeatureCollection' +json.features.should.be.instanceof Array + +#? expected errors +should.not.exist json.geocoding.errors + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.layers.should.eql ["address"] From 63301afeac5a28d6e9cf1b5a79fb00c2befa60e0 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 24 Mar 2016 14:12:52 +0100 Subject: [PATCH 2/2] wow this is easy to get wrong, added a unit test --- query/reverse.js | 3 ++ query/search.js | 1 + .../fixture/reverse_with_source_filtering.js | 51 +++++++++++++++++++ test/unit/query/reverse.js | 17 +++++++ 4 files changed, 72 insertions(+) create mode 100644 test/unit/fixture/reverse_with_source_filtering.js diff --git a/query/reverse.js b/query/reverse.js index 3e9c3aa5..13e9263c 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -28,6 +28,9 @@ function generateQuery( clean ){ vs.var( 'size', clean.querySize); } + // sources + vs.var( 'sources', clean.sources); + // focus point to score by distance if( check.number(clean['point.lat']) && check.number(clean['point.lon']) ){ diff --git a/query/search.js b/query/search.js index 1db1a10a..9f0a792c 100644 --- a/query/search.js +++ b/query/search.js @@ -51,6 +51,7 @@ function generateQuery( clean ){ // input text vs.var( 'input:name', clean.text ); + // sources vs.var( 'sources', clean.sources); // size diff --git a/test/unit/fixture/reverse_with_source_filtering.js b/test/unit/fixture/reverse_with_source_filtering.js new file mode 100644 index 00000000..28fce18b --- /dev/null +++ b/test/unit/fixture/reverse_with_source_filtering.js @@ -0,0 +1,51 @@ +var vs = require('../../../query/reverse_defaults'); + +module.exports = { + 'query': { + 'filtered': { + 'query': { + 'bool': { + 'must': [] + } + }, + 'filter': { + 'bool': { + 'must': [ + { + 'geo_distance': { + 'distance': '500km', + 'distance_type': 'plane', + 'optimize_bbox': 'indexed', + '_cache': true, + 'center_point': { + 'lat': 29.49136, + 'lon': -82.50622 + } + } + }, + { + 'terms': { + 'source': ['test'] + } + } + ] + } + } + } + }, + 'sort': [ + '_score', + { + '_geo_distance': { + 'center_point': { + 'lat': 29.49136, + 'lon': -82.50622 + }, + 'order': 'asc', + 'distance_type': 'plane' + } + } + ], + 'size': vs.size, + 'track_scores': true +}; diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index 7e6c2ba1..4060d679 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -108,6 +108,23 @@ module.exports.tests.query = function(test, common) { t.deepEqual(compiled, expected, 'valid reverse query with boundary.country'); t.end(); }); + + test('valid sources filter', function(t) { + var query = generate({ + 'point.lat': 29.49136, + 'point.lon': -82.50622, + 'boundary.circle.lat': 29.49136, + 'boundary.circle.lon': -82.50622, + 'boundary.circle.radius': 500, + 'sources': ['test'] + }); + + 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.end(); + }); }; module.exports.all = function (tape, common) {