mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
672 B
33 lines
672 B
|
|
var queries = require('geopipes-elasticsearch-backend').queries, |
|
sort = require('./sort'); |
|
|
|
function generate( params ){ |
|
|
|
var centroid = { |
|
lat: params.lat, |
|
lon: params.lon |
|
}; |
|
|
|
var query = queries.distance( centroid, { |
|
size: params.size || 1, |
|
sort: true, |
|
distance: '500km' |
|
}); |
|
|
|
query.sort = query.sort.concat( sort( params ) ); |
|
|
|
if ( params.categories && params.categories.length > 0 ) { |
|
addCategoriesFilter( query, params.categories ); |
|
} |
|
|
|
return query; |
|
} |
|
|
|
function addCategoriesFilter( query, categories ) { |
|
query.query.filtered.filter.bool.must.push({ |
|
terms: { category: categories } |
|
}); |
|
} |
|
|
|
module.exports = generate;
|
|
|