Browse Source

adding all admin layers to the search query (including neirhborhood, locality and local_admin)

search-all-admins
Harish Krishna 10 years ago
parent
commit
ef1a4c8aa6
  1. 4
      query/search.js
  2. 103
      test/unit/query/search.js

4
query/search.js

@ -1,6 +1,7 @@
var logger = require('../src/logger'),
queries = require('geopipes-elasticsearch-backend').queries,
get_layers = require('../helper/layers'),
sort = require('../query/sort');
function generate( params ){
@ -33,7 +34,7 @@ function generate( params ){
};
if (params.input_admin) {
var admin_fields = ['admin0', 'admin1', 'admin1_abbr', 'admin2', 'alpha3'];
var admin_fields = get_layers(['admin','admin1_abbr','alpha3']);
query.query.filtered.query.bool.should = [];
admin_fields.forEach(function(admin_field) {
@ -46,6 +47,7 @@ function generate( params ){
}
query.sort = query.sort.concat(sort);
// console.log( JSON.stringify( query, null, 2 ) );
return query;
}

103
test/unit/query/search.js

@ -216,6 +216,109 @@ module.exports.tests.query = function(test, common) {
t.deepEqual(query, expected, 'valid search query');
t.end();
});
test('valid query with an admin component', function(t) {
var query = generate({
input: 'test', input_admin:'usa', size: 10,
lat: 29.49136, lon: -82.50622,
layers: ['test']
});
var expected = {
'query': {
'filtered': {
'query': {
'bool': {
'must': [{
'match': {
'name.default': 'test'
}
}
],
'should': [
{
'match': {
'admin1_abbr': 'usa'
}
},
{
'match': {
'alpha3': 'usa'
}
},
{
'match': {
'admin0': 'usa'
}
},
{
'match': {
'admin1': 'usa'
}
},
{
'match': {
'admin2': 'usa'
}
},
{
'match': {
'neighborhood': 'usa'
}
},
{
'match': {
'locality': 'usa'
}
},
{
'match': {
'local_admin': 'usa'
}
}
]
}
},
'filter': {
'bool': {
'must': [
{
'geo_distance': {
'distance': '50km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': '29.49',
'lon': '-82.51'
}
}
}
]
}
}
}
},
'sort': [
'_score',
{
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
'order': 'asc',
'unit': 'km'
}
}
].concat(sort.slice(1)),
'size': 10,
'track_scores': true
};
t.deepEqual(query, expected, 'valid query with an admin component');
t.end();
});
};
module.exports.all = function (tape, common) {

Loading…
Cancel
Save