mirror of https://github.com/pelias/api.git
Peter Johnson
10 years ago
2 changed files with 31 additions and 9 deletions
@ -0,0 +1,28 @@
|
||||
|
||||
/** |
||||
|
||||
cmd can be any valid ES suggest command |
||||
|
||||
**/ |
||||
|
||||
function service( backend, cmd, cb ){ |
||||
|
||||
// query new backend
|
||||
backend().client.suggest( cmd, function( err, data ){ |
||||
|
||||
// handle backend errors
|
||||
if( err ){ return cb( err ); } |
||||
|
||||
// map returned documents
|
||||
var docs = []; |
||||
if( data && Array.isArray( data.pelias ) && data.pelias.length ){ |
||||
docs = data['pelias'][0].options || []; |
||||
} |
||||
|
||||
// fire callback
|
||||
return cb( null, docs ); |
||||
}); |
||||
|
||||
} |
||||
|
||||
module.exports = service; |
Loading…
Reference in new issue