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.

72 lines
1.8 KiB

var peliasQuery = require('pelias-query'),
defaults = require('./reverse_defaults'),
check = require('check-types');
//------------------------------
// reverse geocode query
//------------------------------
var query = new peliasQuery.layout.FilteredBooleanQuery();
10 years ago
// mandatory matches
query.score( peliasQuery.view.boundary_country, 'must' );
// scoring boost
query.sort( peliasQuery.view.sort_distance );
// non-scoring hard filters
query.filter( peliasQuery.view.boundary_circle );
query.filter( peliasQuery.view.sources );
query.filter( peliasQuery.view.layers );
// --------------------------------
function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults );
// set size
if( clean.querySize ){
vs.var( 'size', clean.querySize);
}
// sources
vs.var( 'sources', clean.sources);
// layers
vs.var( 'layers', clean.layers);
9 years ago
// focus point to score by distance
if( check.number(clean['point.lat']) &&
check.number(clean['point.lon']) ){
vs.set({
'focus:point:lat': clean['point.lat'],
9 years ago
'focus:point:lon': clean['point.lon']
});
}
9 years ago
// bounding circle
// note: the sanitizers will take care of the case
// where point.lan/point.lon are provided in the
9 years ago
// absense of boundary.circle.lat/boundary.circle.lon
if( check.number(clean['boundary.circle.lat']) &&
check.number(clean['boundary.circle.lon']) &&
check.number(clean['boundary.circle.radius']) ){
vs.set({
'boundary:circle:lat': clean['boundary.circle.lat'],
'boundary:circle:lon': clean['boundary.circle.lon'],
'boundary:circle:radius': clean['boundary.circle.radius'] + 'km'
});
}
// boundary country
9 years ago
if( check.string(clean['boundary.country']) ){
vs.set({
9 years ago
'boundary:country': clean['boundary.country']
});
}
return query.render( vs );
}
module.exports = generateQuery;