Browse Source

added boundary.country to search and reverse queries (with test fixtures)

pull/253/head
Stephen Hess 9 years ago
parent
commit
13635a2c16
  1. 10
      query/reverse.js
  2. 1
      query/search.js
  3. 4
      sanitiser/reverse.js
  4. 6
      test/unit/fixture/reverse_standard.js
  5. 54
      test/unit/fixture/reverse_with_boundary_country.js
  6. 29
      test/unit/fixture/search_boundary_country.js
  7. 14
      test/unit/query/reverse.js
  8. 9
      test/unit/sanitiser/reverse.js

10
query/reverse.js

@ -7,6 +7,9 @@ var peliasQuery = require('pelias-query'),
//------------------------------
var query = new peliasQuery.layout.FilteredBooleanQuery();
// mandatory matches
query.score( peliasQuery.view.boundary_country, 'must' );
// scoring boost
query.sort( peliasQuery.view.sort_distance );
@ -49,6 +52,13 @@ function generateQuery( clean ){
});
}
// boundary country
if( clean.boundary && clean.boundary.country ){
vs.set({
'boundary:country': clean.boundary.country
});
}
return query.render( vs );
}

1
query/search.js

@ -98,7 +98,6 @@ function generateQuery( clean ){
}
// boundary country
// @todo: change these to the correct request variable names
if( clean.boundary && clean.boundary.country ){
vs.set({
'boundary:country': clean.boundary.country

4
sanitiser/reverse.js

@ -6,7 +6,8 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'),
size: require('../sanitiser/_size'),
details: require('../sanitiser/_details'),
geo_reverse: require('../sanitiser/_geo_reverse'),
categories: require('../sanitiser/_categories')
categories: require('../sanitiser/_categories'),
boundary_country: require('../sanitiser/_boundary_country'),
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
@ -25,4 +26,3 @@ module.exports.middleware = function( req, res, next ){
next();
});
};

6
test/unit/fixture/reverse_standard.js

@ -3,7 +3,9 @@ module.exports = {
'query': {
'filtered': {
'query': {
'bool': {}
'bool': {
'must': []
}
},
'filter': {
'bool': {
@ -40,4 +42,4 @@ module.exports = {
],
'size': 1,
'track_scores': true
};
};

54
test/unit/fixture/reverse_with_boundary_country.js

@ -0,0 +1,54 @@
module.exports = {
'query': {
'filtered': {
'query': {
'bool': {
'must': [
{
'match': {
'alpha3': {
'analyzer': 'standard',
'query': 'ABC'
}
}
}
]
}
},
'filter': {
'bool': {
'must': [
{
'geo_distance': {
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
}
}
]
}
}
}
},
'sort': [
'_score',
{
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
'order': 'asc',
'distance_type': 'plane'
}
}
],
'size': 1,
'track_scores': true
};

29
test/unit/fixture/search_boundary_country.js

@ -5,23 +5,24 @@ module.exports = {
'query': {
'bool': {
'must': [
{
'match': {
'alpha3': {
'analyzer': 'standard',
'query': 'ABC'
{
'match': {
'alpha3': {
'analyzer': 'standard',
'query': 'ABC'
}
}
}
},
{
'match': {
'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasOneEdgeGram'
},
{
'match': {
'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasOneEdgeGram'
}
}
}
}],
],
'should': [{
'match': {
'phrase.default': {

14
test/unit/query/reverse.js

@ -60,6 +60,20 @@ module.exports.tests.query = function(test, common) {
});
t.end();
});
test('valid boundary.country reverse search', function(t) {
var query = generate({
lat: 29.49136, lon: -82.50622,
boundary: { country: 'ABC' }
});
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.end();
});
};
module.exports.all = function (tape, common) {

9
test/unit/sanitiser/reverse.js

@ -9,7 +9,8 @@ var reverse = require('../../../sanitiser/reverse'),
lon: 0,
size: 10,
details: true,
categories: []
categories: [],
boundary: { country: undefined }
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
@ -30,7 +31,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
var expected = ['layers', 'sources', 'size', 'details', 'geo_reverse', 'categories'];
var expected = ['layers', 'sources', 'size', 'details', 'geo_reverse', 'categories', 'boundary_country'];
t.deepEqual(Object.keys(reverse.sanitiser_list), expected);
t.end();
});
@ -57,7 +58,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.lat = parseFloat( lat );
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly (' + lat + ')');
t.equal(clean.lat, parseFloat(lat), 'clean set correctly (' + lat + ')');
});
});
t.end();
@ -84,7 +85,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.lon = parseFloat( lon );
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly (' + lon + ')');
t.equal(clean.lon, parseFloat(lon), 'clean set correctly (' + lon + ')');
});
});
t.end();

Loading…
Cancel
Save