Skip to content

Commit

Permalink
Merge pull request #58 from pelias/structured-postalcodes
Browse files Browse the repository at this point in the history
Add postalcode-only support to structured queries
  • Loading branch information
Diana Shkolnikov authored Mar 16, 2017
2 parents 784d3e7 + 92cbda8 commit f566d5b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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 );

Expand All @@ -453,6 +475,9 @@ Layout.prototype.render = function( vs ){
}
funcScoreShould.push(addStreet(vs));
}
if (vs.isset('input:postcode')) {
funcScoreShould.push(addPostCode(vs));
}
if (vs.isset('input:neighbourhood')) {
funcScoreShould.push(addNeighbourhood(vs));
}
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/structuredFallbackQuery/address_with_postcode.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@
}
}
}
},
{
"bool": {
"_name": "fallback.postalcode",
"must": [
{
"multi_match": {
"query": "postcode value",
"type": "phrase",
"fields": ["parent.postalcode"]
}
}
],
"filter": {
"term": {
"layer": "postalcode"
}
}
}
}
]
}
Expand Down

0 comments on commit f566d5b

Please sign in to comment.