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) { function getQuery(vs) {
if (hasStreet(vs) || isCityStateOnlyWithOptionalCountry(vs)) { if (hasStreet(vs) || isCountyRegion(vs) || isCityStateOnlyWithOptionalCountry(vs)) {
return { return {
type: 'fallback', type: 'fallback',
body: fallbackQuery.render(vs) body: fallbackQuery.render(vs)
@ -130,13 +130,24 @@ function getQuery(vs) {
// returning undefined is a signal to a later step that the addressit-parsed // returning undefined is a signal to a later step that the addressit-parsed
// query should be queried for // query should be queried for
return undefined; return undefined;
} }
function hasStreet(vs) { function hasStreet(vs) {
return vs.isset('input:street'); 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) { function isCityStateOnlyWithOptionalCountry(vs) {
var isSet = function(layer) { var isSet = function(layer) {
return vs.isset('input:' + 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) { module.exports.all = function (tape, common) {

Loading…
Cancel
Save