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;
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']
}

2
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',

16
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;

Loading…
Cancel
Save