Browse Source

Added postalcode rules for node-postal call and fallbacks

pull/974/head
Adam Rousell 7 years ago
parent
commit
f86ee4a40f
  1. 20
      middleware/confidenceScoreFallback.js
  2. 2
      middleware/trimByGranularityStructured.js
  3. 16
      query/search.js

20
middleware/confidenceScoreFallback.js

@ -76,6 +76,8 @@ function checkFallbackLevel(req, hit) {
return 0.8; return 0.8;
case 'street': case 'street':
return 0.8; return 0.8;
case 'postalcode':
return 0.8;
case 'localadmin': case 'localadmin':
case 'locality': case 'locality':
case 'borough': case 'borough':
@ -137,38 +139,44 @@ const fallbackRules = [
expectedLayers: ['street'] expectedLayers: ['street']
}, },
{ {
name: 'neighbourhood', name: 'postalcode',
notSet: ['query', 'number', 'street'], notSet: ['query', 'number', 'street'],
set: ['postalcode'],
expectedLayers: ['postalcode']
},
{
name: 'neighbourhood',
notSet: ['query', 'number', 'street', 'postalcode'],
set: ['neighbourhood'], set: ['neighbourhood'],
expectedLayers: ['neighbourhood'] expectedLayers: ['neighbourhood']
}, },
{ {
name: 'borough', name: 'borough',
notSet: ['query', 'number', 'street', 'neighbourhood'], notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood'],
set: ['borough'], set: ['borough'],
expectedLayers: ['borough'] expectedLayers: ['borough']
}, },
{ {
name: 'city', name: 'city',
notSet: ['query', 'number', 'street', 'neighbourhood', 'borough'], notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough'],
set: ['city'], set: ['city'],
expectedLayers: ['borough', 'locality', 'localadmin'] expectedLayers: ['borough', 'locality', 'localadmin']
}, },
{ {
name: 'county', name: 'county',
notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city'], notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city'],
set: ['county'], set: ['county'],
expectedLayers: ['county'] expectedLayers: ['county']
}, },
{ {
name: 'state', name: 'state',
notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city', 'county'], notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city', 'county'],
set: ['state'], set: ['state'],
expectedLayers: ['region'] expectedLayers: ['region']
}, },
{ {
name: 'country', name: 'country',
notSet: ['query', 'number', 'street', 'neighbourhood', 'borough', 'city', 'county', 'state'], notSet: ['query', 'number', 'street', 'postalcode', 'neighbourhood', 'borough', 'city', 'county', 'state'],
set: ['country'], set: ['country'],
expectedLayers: ['country'] expectedLayers: ['country']
} }

2
middleware/trimByGranularityStructured.js

@ -24,6 +24,7 @@ const layers = [
'venue', 'venue',
'address', 'address',
'street', 'street',
'postalcode',
'neighbourhood', 'neighbourhood',
['borough', 'locality'], ['borough', 'locality'],
'localadmin', 'localadmin',
@ -46,6 +47,7 @@ const explicit_borough_layers = [
'venue', 'venue',
'address', 'address',
'street', 'street',
'postalcode',
'neighbourhood', 'neighbourhood',
'borough', 'borough',
'locality', 'locality',

16
query/search.js

@ -135,7 +135,7 @@ function getQuery(vs) {
logger.info(`[query:search] [search_input_type:${determineQueryType(vs)}]`); logger.info(`[query:search] [search_input_type:${determineQueryType(vs)}]`);
if (hasStreet(vs) || isPostalCodeOnly(vs)) { if (hasStreet(vs) || isPostalCodeOnly(vs) || isPostalCodeWithCountry(vs)) {
return { return {
type: 'fallback', type: 'fallback',
body: fallbackQuery.render(vs) 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; module.exports = generateQuery;

Loading…
Cancel
Save