From 41362f83c2e5f2702b5eb3845829125b83c0e12e Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 4 Nov 2016 14:57:59 -0400 Subject: [PATCH] Support county + region queries for fallback query --- query/search.js | 15 +++++++++++++-- test/unit/query/search.js | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/query/search.js b/query/search.js index 945276e9..3a09e5f8 100644 --- a/query/search.js +++ b/query/search.js @@ -120,7 +120,7 @@ function generateQuery( clean ){ } function getQuery(vs) { - if (hasStreet(vs) || isCityStateOnlyWithOptionalCountry(vs)) { + if (hasStreet(vs) || isCountyRegion(vs) || isCityStateOnlyWithOptionalCountry(vs)) { return { type: 'fallback', body: fallbackQuery.render(vs) @@ -130,13 +130,24 @@ function getQuery(vs) { // returning undefined is a signal to a later step that the addressit-parsed // query should be queried for return undefined; - } function hasStreet(vs) { return vs.isset('input:street'); } +function isCountyRegion(vs) { + var isSet = function(layer) { + return vs.isset('input:' + layer); + }; + + var allowedFields = ['county', 'region']; + var disallowedFields = ['query', 'category', 'housenumber', 'street', + 'neighbourhood', 'borough', 'postcode', 'locality']; + + return allowedFields.every(isSet) && !disallowedFields.some(isSet); +} + function isCityStateOnlyWithOptionalCountry(vs) { var isSet = function(layer) { return vs.isset('input:' + layer); diff --git a/test/unit/query/search.js b/test/unit/query/search.js index f16a79ae..ac3b8be3 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -445,6 +445,19 @@ module.exports.tests.city_state = function(test, common) { }); + test('county/region(state) should return a query', function(t) { + var clean = { + parsed_text: { + county: 'county value', + state: 'state value' + } + }; + + var query = generate(clean); + + t.ok(query, 'should return a query'); + t.end(); + }); }; module.exports.all = function (tape, common) {