Browse Source

using elasticsearch-backend#centroid-optional queries for search

pull/66/head
Harish Krishna 10 years ago
parent
commit
a4bd350f2e
  1. 2
      package.json
  2. 52
      query/search.js

2
package.json

@ -36,7 +36,7 @@
"express": "^4.8.8", "express": "^4.8.8",
"geojson": "^0.2.0", "geojson": "^0.2.0",
"geojson-extent": "^0.3.1", "geojson-extent": "^0.3.1",
"geopipes-elasticsearch-backend": "git://github.com/geopipes/elasticsearch-backend#geo_bbox", "geopipes-elasticsearch-backend": "git://github.com/geopipes/elasticsearch-backend#centroid-optional",
"is-object": "^1.0.1", "is-object": "^1.0.1",
"pelias-esclient": "0.0.25", "pelias-esclient": "0.0.25",
"toobusy": "^0.2.4" "toobusy": "^0.2.4"

52
query/search.js

@ -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 = {

Loading…
Cancel
Save