Browse Source

Merge pull request #15 from pelias/refactor_reverse

refactor reverse query
pull/17/head
Peter Johnson @insertcoffee 10 years ago
parent
commit
6c6275f70b
  1. 30
      query/reverse.js
  2. 48
      test/unit/query/reverse.js

30
query/reverse.js

@ -1,31 +1,15 @@
var logger = require('../src/logger');
// Build pelias search query var logger = require('../src/logger'),
queries = require('geopipes-elasticsearch-backend').queries;
function generate( params ){ function generate( params ){
var cmd = { var centroid = {
"query":{ lat: params.lat,
"filtered" : { lon: params.lon
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1km",
"center_point" : {
"lat": params.lat,
"lon": params.lon
}
}
}
}
},
"size": 1
}; };
// logger.log( 'cmd', JSON.stringify( cmd, null, 2 ) ); return queries.distance( centroid, { size: 1 } );
return cmd;
} }
module.exports = generate; module.exports = generate;

48
test/unit/query/reverse.js

@ -15,26 +15,48 @@ module.exports.tests.query = function(test, common) {
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622 lat: 29.49136, lon: -82.50622
}); });
var expected = { var expected = {
query:{ 'query': {
filtered : { 'filtered': {
query : { 'query': {
match_all : {} 'match_all': {}
}, },
filter : { 'filter': {
geo_distance : { 'bool': {
distance : '1km', 'must': [
center_point : { {
lat: 29.49136, 'geo_distance': {
lon: -82.50622 'distance': '50km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': '29.49',
'lon': '-82.51'
}
} }
} }
]
}
} }
} }
}, },
size: 1 'sort': [
{
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
'order': 'asc',
'unit': 'km'
}
}
],
'size': 1
}; };
t.deepEqual(query, expected, 'valid reverse query'); t.deepEqual(query, expected, 'valid reverse query');
t.end(); t.end();
}); });

Loading…
Cancel
Save