Browse Source

wow this is easy to get wrong, added a unit test

pull/469/head
Peter Johnson 9 years ago committed by Julian Simioni
parent
commit
63301afeac
  1. 3
      query/reverse.js
  2. 1
      query/search.js
  3. 51
      test/unit/fixture/reverse_with_source_filtering.js
  4. 17
      test/unit/query/reverse.js

3
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']) ){

1
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

51
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
};

17
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) {

Loading…
Cancel
Save