|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
|
|
|
|
|
var geojsonify = require('../helper/geojsonify').suggest; |
|
|
|
|
var async = require('async'); |
|
|
|
|
|
|
|
|
|
function setup( backend, query ){ |
|
|
|
|
|
|
|
|
@ -11,13 +12,10 @@ function setup( backend, query ){
|
|
|
|
|
backend = backend || require('../src/backend'); |
|
|
|
|
var query_admin = require('../query/suggest_admin'); |
|
|
|
|
var query_poi = require('../query/suggest_poi'); |
|
|
|
|
|
|
|
|
|
// **query_poi** command
|
|
|
|
|
var cmd = { |
|
|
|
|
index: 'pelias', |
|
|
|
|
body: query_poi( req.clean ) |
|
|
|
|
index: 'pelias' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var query_backend = function(cmd, callback) { |
|
|
|
|
// query backend
|
|
|
|
|
backend().client.suggest( cmd, function( err, data ){ |
|
|
|
|
|
|
|
|
@ -31,27 +29,23 @@ function setup( backend, query ){
|
|
|
|
|
docs = data['pelias'][0].options || []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// **query_admin** command
|
|
|
|
|
var cmd = { |
|
|
|
|
index: 'pelias', |
|
|
|
|
body: query_admin( req.clean ) |
|
|
|
|
callback(null, docs); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// query backend
|
|
|
|
|
backend().client.suggest( cmd, function( err, data ){ |
|
|
|
|
|
|
|
|
|
var docs2 = []; |
|
|
|
|
|
|
|
|
|
// handle backend errors
|
|
|
|
|
if( err ){ return next( err ); } |
|
|
|
|
|
|
|
|
|
// map response to a valid FeatureCollection
|
|
|
|
|
if( data && Array.isArray( data.pelias ) && data.pelias.length ){ |
|
|
|
|
docs2 = data['pelias'][0].options || []; |
|
|
|
|
async.parallel({ |
|
|
|
|
admin: function(callback){ |
|
|
|
|
cmd.body = query_admin( req.clean ); |
|
|
|
|
query_backend(cmd, callback); |
|
|
|
|
}, |
|
|
|
|
poi: function(callback){ |
|
|
|
|
cmd.body = query_poi( req.clean ); |
|
|
|
|
query_backend(cmd, callback); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** --- combine 2 doc sets --- **/ |
|
|
|
|
var combined = docs2.slice(0, 3).concat(docs); |
|
|
|
|
}, |
|
|
|
|
function(err, results) { |
|
|
|
|
// results is now equals to: {admin: docs, poi: docs}
|
|
|
|
|
var combined = results.poi.slice(0, 3).concat(results.admin); |
|
|
|
|
|
|
|
|
|
// convert docs to geojson
|
|
|
|
|
var geojson = geojsonify( combined ); |
|
|
|
@ -61,9 +55,6 @@ function setup( backend, query ){
|
|
|
|
|
|
|
|
|
|
// respond
|
|
|
|
|
return res.status(200).json( geojson ); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|