diff --git a/sanitizer/_synthesize_analysis.js b/sanitizer/_synthesize_analysis.js index f26dfc6a..6c702f9e 100644 --- a/sanitizer/_synthesize_analysis.js +++ b/sanitizer/_synthesize_analysis.js @@ -50,10 +50,7 @@ function sanitize( raw, clean ){ }, {}); - if (isPostalCodeOnly(clean.parsed_text)) { - messages.errors.push('postalcode-only inputs are not supported'); - } - else if (_.isEmpty(Object.keys(clean.parsed_text))) { + if (_.isEmpty(Object.keys(clean.parsed_text))) { messages.errors.push( `at least one of the following fields is required: ${Object.keys(fields).join(', ')}`); } diff --git a/test/unit/fixture/structured_geocoding/fallback.json b/test/unit/fixture/structured_geocoding/fallback.json index cd12a864..58d0ce8c 100644 --- a/test/unit/fixture/structured_geocoding/fallback.json +++ b/test/unit/fixture/structured_geocoding/fallback.json @@ -287,6 +287,75 @@ "boost": 5 } }, + { + "bool": { + "_name": "fallback.postalcode", + "must": [ + { + "multi_match": { + "query": "postalcode value", + "type": "phrase", + "fields": [ + "parent.postalcode" + ] + } + }, + { + "multi_match": { + "query": "city value", + "type": "phrase", + "fields": [ + "parent.locality", + "parent.locality_a", + "parent.localadmin", + "parent.localadmin_a" + ] + } + }, + { + "multi_match": { + "query": "county value", + "type": "phrase", + "fields": [ + "parent.county", + "parent.county_a", + "parent.macrocounty", + "parent.macrocounty_a" + ] + } + }, + { + "multi_match": { + "query": "state value", + "type": "phrase", + "fields": [ + "parent.region", + "parent.region_a", + "parent.macroregion", + "parent.macroregion_a" + ] + } + }, + { + "multi_match": { + "query": "country value", + "type": "phrase", + "fields": [ + "parent.country", + "parent.country_a", + "parent.dependency", + "parent.dependency_a" + ] + } + } + ], + "filter": { + "term": { + "layer": "postalcode" + } + } + } + }, { "bool": { "_name": "fallback.neighbourhood", diff --git a/test/unit/fixture/structured_geocoding/postalcode_only.js b/test/unit/fixture/structured_geocoding/postalcode_only.js new file mode 100644 index 00000000..7dafbaa0 --- /dev/null +++ b/test/unit/fixture/structured_geocoding/postalcode_only.js @@ -0,0 +1,68 @@ +module.exports = { + 'query': { + 'function_score': { + 'query': { + 'filtered': { + 'query': { + 'bool': { + 'should': [ + { + 'bool': { + '_name': 'fallback.postalcode', + 'must': [ + { + 'multi_match': { + 'query': 'postalcode value', + 'type': 'phrase', + 'fields': [ + 'parent.postalcode' + ] + } + } + ], + 'filter': { + 'term': { + 'layer': 'postalcode' + } + } + } + } + ] + } + }, + 'filter': { + 'bool': { + 'must': [] + } + } + } + }, + 'max_boost': 20, + 'functions': [ + { + 'field_value_factor': { + 'modifier': 'log1p', + 'field': 'popularity', + 'missing': 1 + }, + 'weight': 1 + }, + { + 'field_value_factor': { + 'modifier': 'log1p', + 'field': 'population', + 'missing': 1 + }, + 'weight': 2 + } + ], + 'score_mode': 'avg', + 'boost_mode': 'multiply' + } + }, + 'size': 20, + 'track_scores': true, + 'sort': [ + '_score' + ] +}; diff --git a/test/unit/query/structured_geocoding.js b/test/unit/query/structured_geocoding.js index fc5f211a..d93a03aa 100644 --- a/test/unit/query/structured_geocoding.js +++ b/test/unit/query/structured_geocoding.js @@ -188,6 +188,24 @@ module.exports.tests.query = function(test, common) { }); + test('parsed_text with all fields should use FallbackQuery', function(t) { + var clean = { + parsed_text: { + postalcode: 'postalcode value' + } + }; + + var query = generate(clean); + + var compiled = JSON.parse(JSON.stringify(query)); + var expected = require('../fixture/structured_geocoding/postalcode_only'); + + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'structured postalcode only'); + t.end(); + + }); + test('valid boundary.country search', function(t) { var clean = { parsed_text: { diff --git a/test/unit/sanitizer/_synthesize_analysis.js b/test/unit/sanitizer/_synthesize_analysis.js index 97d49b2a..82352c8d 100644 --- a/test/unit/sanitizer/_synthesize_analysis.js +++ b/test/unit/sanitizer/_synthesize_analysis.js @@ -131,7 +131,7 @@ module.exports.tests.text_parser = function(test, common) { const messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); - t.deepEquals(messages.errors, ['postalcode-only inputs are not supported'], 'no errors'); + t.deepEquals(messages.errors, [], 'no errors'); t.deepEquals(messages.warnings, [], 'no warnings'); t.end();