diff --git a/layout/StructuredFallbackQuery.js b/layout/StructuredFallbackQuery.js index 4b7b223..7e21a39 100644 --- a/layout/StructuredFallbackQuery.js +++ b/layout/StructuredFallbackQuery.js @@ -503,7 +503,8 @@ function addPostCode(vs) { vs.var('input:postcode').toString(), 'postalcode', [ - 'parent.postalcode' + 'parent.postalcode', + 'address_parts.zip' ], false ); diff --git a/test/fixtures/structuredFallbackQuery/address_with_postcode.json b/test/fixtures/structuredFallbackQuery/address_with_postcode.json index ea8600b..65769db 100644 --- a/test/fixtures/structuredFallbackQuery/address_with_postcode.json +++ b/test/fixtures/structuredFallbackQuery/address_with_postcode.json @@ -78,7 +78,10 @@ "multi_match": { "query": "postcode value", "type": "phrase", - "fields": ["parent.postalcode"] + "fields": [ + "parent.postalcode", + "address_parts.zip" + ] } } ], diff --git a/test/fixtures/structuredFallbackQuery/postcode.json b/test/fixtures/structuredFallbackQuery/postcode.json new file mode 100644 index 0000000..54111b5 --- /dev/null +++ b/test/fixtures/structuredFallbackQuery/postcode.json @@ -0,0 +1,44 @@ +{ + "query": { + "function_score": { + "query": { + "bool": { + "minimum_should_match": 1, + "should": [ + { + "bool": { + "_name": "fallback.postalcode", + "must": [ + { + "multi_match": { + "query": "postcode value", + "type": "phrase", + "fields": [ + "parent.postalcode", + "address_parts.zip" + ] + } + } + ], + "filter": { + "term": { + "layer": "postalcode" + } + } + } + } + ] + } + }, + "max_boost": 20, + "functions": [], + "score_mode": "avg", + "boost_mode": "multiply" + } + }, + "sort": [ + "_score" + ], + "size": "size value", + "track_scores": "track_scores value" +} \ No newline at end of file diff --git a/test/layout/StructuredFallbackQuery.js b/test/layout/StructuredFallbackQuery.js index 838bf57..abba14c 100644 --- a/test/layout/StructuredFallbackQuery.js +++ b/test/layout/StructuredFallbackQuery.js @@ -36,6 +36,22 @@ module.exports.tests.base_render = function(test, common) { }); + test('VariableStore with postcode only', function(t) { + var query = new StructuredFallbackQuery(); + + var vs = new VariableStore(); + vs.var('size', 'size value'); + vs.var('track_scores', 'track_scores value'); + vs.var('input:postcode', 'postcode value'); + + var actual = JSON.parse(JSON.stringify(query.render(vs))); + var expected = require('../fixtures/structuredFallbackQuery/postcode.json'); + + t.deepEquals(actual, expected); + t.end(); + + }); + test('VariableStore with address and less granular fields should include all others', function(t) { var query = new StructuredFallbackQuery();