From e930786085f943a5458642af02c421703728803d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 16 Apr 2024 15:41:26 +0200 Subject: [PATCH 1/2] test: add structuredFallbackQuery postcode-only test --- .../structuredFallbackQuery/postcode.json | 43 +++++++++++++++++++ test/layout/StructuredFallbackQuery.js | 16 +++++++ 2 files changed, 59 insertions(+) create mode 100644 test/fixtures/structuredFallbackQuery/postcode.json diff --git a/test/fixtures/structuredFallbackQuery/postcode.json b/test/fixtures/structuredFallbackQuery/postcode.json new file mode 100644 index 0000000..75c7b1d --- /dev/null +++ b/test/fixtures/structuredFallbackQuery/postcode.json @@ -0,0 +1,43 @@ +{ + "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" + ] + } + } + ], + "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(); From 0c510a34162433a13da61fe7ebea13ca4ed547d2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 16 Apr 2024 15:26:34 +0200 Subject: [PATCH 2/2] feat(structured): use both parent.postalcode & address_parts.zip for postalcode subqueries. --- layout/StructuredFallbackQuery.js | 3 ++- .../structuredFallbackQuery/address_with_postcode.json | 5 ++++- test/fixtures/structuredFallbackQuery/postcode.json | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) 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 index 75c7b1d..54111b5 100644 --- a/test/fixtures/structuredFallbackQuery/postcode.json +++ b/test/fixtures/structuredFallbackQuery/postcode.json @@ -14,7 +14,8 @@ "query": "postcode value", "type": "phrase", "fields": [ - "parent.postalcode" + "parent.postalcode", + "address_parts.zip" ] } }