Browse Source

Support county + region queries for fallback query

county-fallback
Julian Simioni 8 years ago
parent
commit
41362f83c2
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 15
      query/search.js
  2. 13
      test/unit/query/search.js

15
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);

13
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) {

Loading…
Cancel
Save