From 27e2c4e5b8bf0eebf2aebbcad9d4eb5405464a16 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 3 Nov 2014 17:54:22 +0000 Subject: [PATCH] migrate outputGenerator from pelias/suggester-pipeline --- helper/geojsonify.js | 9 +- helper/outputGenerator.js | 37 +++++ helper/outputSchema.json | 14 ++ test/unit/controller/search.js | 6 +- test/unit/controller/suggest.js | 6 +- test/unit/helper/geojsonify.js | 2 +- test/unit/helper/outputSchema.js | 55 +++++++ test/unit/mock/alpha3.json | 251 +++++++++++++++++++++++++++++++ test/unit/run.js | 3 +- 9 files changed, 372 insertions(+), 11 deletions(-) create mode 100644 helper/outputGenerator.js create mode 100644 helper/outputSchema.json create mode 100644 test/unit/helper/outputSchema.js create mode 100644 test/unit/mock/alpha3.json diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 196bd18f..7bdae990 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -1,5 +1,6 @@ -var GeoJSON = require('geojson'); +var GeoJSON = require('geojson'), + outputGenerator = require('./outputGenerator'); function search( docs ){ @@ -37,10 +38,8 @@ function search( docs ){ if( doc.locality ){ output.locality = doc.locality; } if( doc.neighborhood ){ output.neighborhood = doc.neighborhood; } - // map suggest output - if( doc.suggest && doc.suggest.output ){ - output.text = doc.suggest.output; - } + // generate region-specific text string + output.text = outputGenerator( doc ); return output; diff --git a/helper/outputGenerator.js b/helper/outputGenerator.js new file mode 100644 index 00000000..42fa1279 --- /dev/null +++ b/helper/outputGenerator.js @@ -0,0 +1,37 @@ + +var schemas = require('./outputSchema.json'); + +module.exports = function( record ){ + + var adminParts = []; + + var schema = schemas.default; + + if (record.alpha3 && record.alpha3.length && schemas[record.alpha3]) { + schema = schemas[record.alpha3]; + } + + var buildOutput = function(parts, schemaArr, record) { + for (var i=0; i