diff --git a/layout/FallbackQuery.js b/layout/FallbackQuery.js index 2eb857d..f8cbcb1 100644 --- a/layout/FallbackQuery.js +++ b/layout/FallbackQuery.js @@ -466,6 +466,28 @@ function addCountry(vs) { } +function addPostCode(vs) { + var o = addPrimary( + vs.var('input:postcode').toString(), + 'postalcode', + [ + 'parent.postalcode' + ], + false + ); + + // same position in hierarchy as borough according to WOF + // https://github.com/whosonfirst/whosonfirst-placetypes#here-is-a-pretty-picture + addSecLocality(vs, o); + addSecCounty(vs, o); + addSecRegion(vs, o); + addSecCountry(vs, o); + + return o; + +} + + Layout.prototype.render = function( vs ){ var q = Layout.base( vs ); @@ -477,6 +499,9 @@ Layout.prototype.render = function( vs ){ if (vs.isset('input:housenumber') && vs.isset('input:street')) { funcScoreShould.push(addHouseNumberAndStreet(vs)); } + if (vs.isset('input:postcode')) { + funcScoreShould.push(addPostCode(vs)); + } if (vs.isset('input:street')) { funcScoreShould.push(addStreet(vs)); } diff --git a/test/fixtures/fallbackQuery_address_with_postcode.json b/test/fixtures/fallbackQuery_address_with_postcode.json index ffb7b16..3834509 100644 --- a/test/fixtures/fallbackQuery_address_with_postcode.json +++ b/test/fixtures/fallbackQuery_address_with_postcode.json @@ -36,6 +36,25 @@ } } }, + { + "bool": { + "_name": "fallback.postalcode", + "must": [ + { + "multi_match": { + "query": "postcode value", + "type": "phrase", + "fields": ["parent.postalcode"] + } + } + ], + "filter": { + "term": { + "layer": "postalcode" + } + } + } + }, { "bool": { "_name": "fallback.street",