|
|
@ -4,59 +4,19 @@ var logger = require('../src/logger'), |
|
|
|
|
|
|
|
|
|
|
|
function generate( params ){ |
|
|
|
function generate( params ){ |
|
|
|
|
|
|
|
|
|
|
|
var query = { |
|
|
|
var centroid = null; |
|
|
|
'query': { |
|
|
|
|
|
|
|
'filtered': { |
|
|
|
|
|
|
|
'query': { |
|
|
|
|
|
|
|
'match_all': {} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'filter' : { |
|
|
|
|
|
|
|
'bool': { |
|
|
|
|
|
|
|
'must': [] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'size': params.size |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: DRY (the following lines are repeated here and in geopipes-elasticsearchbackend)
|
|
|
|
|
|
|
|
// query/geo_bbox - cleanup necessary #techdebt
|
|
|
|
|
|
|
|
if (params.bbox) { |
|
|
|
|
|
|
|
var options = { |
|
|
|
|
|
|
|
top : Number( params.bbox.top ).toFixed(2), // @note: make filter cachable
|
|
|
|
|
|
|
|
right : Number( params.bbox.right ).toFixed(2), // precision max ~1.113km off
|
|
|
|
|
|
|
|
bottom: Number( params.bbox.bottom ).toFixed(2), |
|
|
|
|
|
|
|
left : Number( params.bbox.left ).toFixed(2), |
|
|
|
|
|
|
|
size: params.size || 1, |
|
|
|
|
|
|
|
field: params.field || 'center_point' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var filter = { |
|
|
|
|
|
|
|
'geo_bounding_box' : { |
|
|
|
|
|
|
|
'_cache': true // Speed up duplicate queries. Memory impact?
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filter.geo_bounding_box[ options.field ] = { |
|
|
|
|
|
|
|
'top' : options.top, |
|
|
|
|
|
|
|
'right' : options.right, |
|
|
|
|
|
|
|
'bottom': options.bottom, |
|
|
|
|
|
|
|
'left' : options.left, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
query.query.filtered.filter.bool.must.push( filter ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( params.lat && params.lon ){ |
|
|
|
if ( params.lat && params.lon ){ |
|
|
|
var centroid = { |
|
|
|
centroid = { |
|
|
|
lat: params.lat, |
|
|
|
lat: params.lat, |
|
|
|
lon: params.lon |
|
|
|
lon: params.lon |
|
|
|
}; |
|
|
|
}; |
|
|
|
query = queries.distance( centroid, { size: params.size } ); |
|
|
|
}
|
|
|
|
if (params.bbox) { |
|
|
|
|
|
|
|
query = queries.bbox ( centroid, { size: params.size, bbox: params.bbox } ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = queries.distance( centroid, { size: params.size } ); |
|
|
|
|
|
|
|
if (params.bbox) { |
|
|
|
|
|
|
|
query = queries.bbox ( centroid, { size: params.size, bbox: params.bbox } ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// add search condition to distance query
|
|
|
|
// add search condition to distance query
|
|
|
|
query.query.filtered.query = { |
|
|
|
query.query.filtered.query = { |
|
|
|