diff --git a/package.json b/package.json index 14a5a0a1..9c81172b 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "pelias-config": "2.13.0", "pelias-dbclient": "2.2.5", "pelias-logger": "0.3.0", - "pelias-model": "5.2.0", + "pelias-model": "sweco-semhul/model#adding-address-unit", "pelias-wof-admin-lookup": "4.1.2", "through2": "^2.0.0", "through2-sink": "^1.0.0", diff --git a/schema/address_osm.js b/schema/address_osm.js index 25a00287..d59e83fc 100644 --- a/schema/address_osm.js +++ b/schema/address_osm.js @@ -11,7 +11,8 @@ **/ var OSM_SCHEMA = { - 'postal_code': 'zip' + 'postal_code': 'zip', + 'addr:unit': 'unit' }; module.exports = OSM_SCHEMA; \ No newline at end of file diff --git a/stream/address_extractor.js b/stream/address_extractor.js index d344651f..4b5ad299 100644 --- a/stream/address_extractor.js +++ b/stream/address_extractor.js @@ -61,9 +61,16 @@ module.exports = function(){ peliasLogger.debug('[address_extractor] found multiple house numbers: ', streetnumbers); } + // If unit is set to an address add it to default name since streetno and street will be the same + var name = [ streetno, doc.address_parts.street ]; + if( doc.address_parts.hasOwnProperty('unit') ) { + name.push( doc.address_parts.unit ); + } + name = name.join(' '); + // copy data to new document record = new Document( 'openstreetmap', 'address', newid.join(':') ) - .setName( 'default', streetno + ' ' + doc.address_parts.street ) + .setName( 'default', name ) .setCentroid( doc.getCentroid() ); setProperties( record, doc ); @@ -112,7 +119,7 @@ module.exports = function(){ }; // properties to map from the osm record to the pelias doc -var addrProps = [ 'name', 'number', 'street', 'zip' ]; +var addrProps = [ 'name', 'unit', 'number', 'street', 'zip' ]; // call document setters and ignore non-fatal errors function setProperties( record, doc ){ diff --git a/test/stream/tag_mapper.js b/test/stream/tag_mapper.js index 4b28d004..656dad35 100644 --- a/test/stream/tag_mapper.js +++ b/test/stream/tag_mapper.js @@ -146,10 +146,11 @@ module.exports.tests.lowercase_keys = function(test, common) { module.exports.tests.osm_schema = function(test, common) { test('maps - osm schema', function(t) { var doc = new Document('a','b',1); - doc.setMeta('tags', { postal_code: 'AAA' }); + doc.setMeta('tags', { postal_code: 'AAA', 'addr:unit': 'BBB' }); var stream = mapper(); stream.pipe( through.obj( function( doc, enc, next ){ t.equal(doc.getAddress('zip'), 'AAA', 'correctly mapped'); + t.equal(doc.getAddress('unit'), 'BBB', 'correctly mapped'); t.end(); // test will fail if not called (or called twice). next(); }));