diff --git a/middleware/confidenceScoreFallback.js b/middleware/confidenceScoreFallback.js index 472dd841..488bd721 100644 --- a/middleware/confidenceScoreFallback.js +++ b/middleware/confidenceScoreFallback.js @@ -76,6 +76,8 @@ function checkFallbackLevel(req, hit) { return 0.8; case 'street': return 0.8; + case 'postalcode': + return 0.8; case 'localadmin': case 'locality': case 'borough': @@ -137,38 +139,44 @@ const fallbackRules = [ expectedLayers: ['street'] }, { - name: 'neighbourhood', + name: 'postalcode', notSet: ['query', 'number', 'street'], + set: ['postalcode'], + expectedLayers: ['postalcode'] + }, + { + name: 'neighbourhood', + notSet: ['query', 'number', 'street', 'postalcode'], set: ['neighbourhood'], expectedLayers: ['neighbourhood'] }, { name: 'borough', - notSet: ['query', 'number', 'street', 'neighbourhood'], + notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood'], set: ['borough'], expectedLayers: ['borough'] }, { name: 'city', - notSet: ['query', 'number', 'street', 'neighbourhood', 'borough'], + notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough'], set: ['city'], expectedLayers: ['borough', 'locality', 'localadmin'] }, { name: 'county', - notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city'], + notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city'], set: ['county'], expectedLayers: ['county'] }, { name: 'state', - notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city', 'county'], + notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city', 'county'], set: ['state'], expectedLayers: ['region'] }, { name: 'country', - notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city', 'county', 'state'], + notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city', 'county', 'state'], set: ['country'], expectedLayers: ['country'] } diff --git a/middleware/trimByGranularityStructured.js b/middleware/trimByGranularityStructured.js index 1fe94ce8..5bf4685b 100644 --- a/middleware/trimByGranularityStructured.js +++ b/middleware/trimByGranularityStructured.js @@ -24,6 +24,7 @@ const layers = [ 'venue', 'address', 'street', + 'postalcode', 'neighbourhood', ['borough', 'locality'], 'localadmin', @@ -46,6 +47,7 @@ const explicit_borough_layers = [ 'venue', 'address', 'street', + 'postalcode', 'neighbourhood', 'borough', 'locality', diff --git a/query/search.js b/query/search.js index ce3ac639..991e239c 100644 --- a/query/search.js +++ b/query/search.js @@ -135,7 +135,7 @@ function getQuery(vs) { logger.info(`[query:search] [search_input_type:${determineQueryType(vs)}]`); - if (hasStreet(vs) || isPostalCodeOnly(vs)) { + if (hasStreet(vs) || isPostalCodeOnly(vs) || isPostalCodeWithCountry(vs)) { return { type: 'fallback', body: fallbackQuery.render(vs) @@ -182,4 +182,18 @@ function isPostalCodeOnly(vs) { } + +function isPostalCodeWithCountry(vs) { + var isSet = (layer) => { + return vs.isset(`input:${layer}`); + }; + + var allowedFields = ['postcode', 'country']; + var disallowedFields = ['query', 'category', 'housenumber', 'street', 'locality', + 'neighbourhood', 'borough', 'county', 'region']; + + return allowedFields.every(isSet) && + !disallowedFields.some(isSet); +} + module.exports = generateQuery;