From a4bd350f2e6c47ece9b1234a80dd7e7b52284501 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 29 Jan 2015 17:56:30 -0500 Subject: [PATCH] using elasticsearch-backend#centroid-optional queries for search --- package.json | 2 +- query/search.js | 54 +++++++------------------------------------------ 2 files changed, 8 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 8e635e1f..ffaa5841 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "express": "^4.8.8", "geojson": "^0.2.0", "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", "pelias-esclient": "0.0.25", "toobusy": "^0.2.4" diff --git a/query/search.js b/query/search.js index 2805a1fa..4ccc9f6d 100644 --- a/query/search.js +++ b/query/search.js @@ -4,59 +4,19 @@ var logger = require('../src/logger'), function generate( params ){ - var query = { - '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 ); - } + var centroid = null; if ( params.lat && params.lon ){ - var centroid = { + centroid = { lat: params.lat, 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 query.query.filtered.query = {