Browse Source

removed unreachable paths in query/search

pull/912/head
Stephen Hess 8 years ago
parent
commit
1fef7ac41c
  1. 39
      query/search.js
  2. 7
      test/unit/query/search.js

39
query/search.js

@ -135,10 +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) || if (hasStreet(vs) || isPostalCodeOnly(vs)) {
isCityStateOnlyWithOptionalCountry(vs) ||
isCityCountryOnly(vs) ||
isPostalCodeOnly(vs)) {
return { return {
type: 'fallback', type: 'fallback',
body: fallbackQuery.render(vs) body: fallbackQuery.render(vs)
@ -162,7 +159,8 @@ function determineQueryType(vs) {
return 'venue'; return 'venue';
} }
else if (['neighbourhood', 'borough', 'postcode', 'county', 'region','country'].some( else if (['neighbourhood', 'borough', 'postcode', 'county', 'region','country'].some(
(layer)=> { return vs.isset(`input:${layer}`);})) { layer => vs.isset(`input:${layer}`)
)) {
return 'admin'; return 'admin';
} }
return 'other'; return 'other';
@ -172,37 +170,8 @@ function hasStreet(vs) {
return vs.isset('input:street'); return vs.isset('input:street');
} }
function isCityStateOnlyWithOptionalCountry(vs) {
var isSet = (layer) => {
return vs.isset(`input:${layer}`);
};
var allowedFields = ['locality', 'region'];
var disallowedFields = ['query', 'category', 'housenumber', 'street',
'neighbourhood', 'borough', 'postcode', 'county'];
return allowedFields.every(isSet) && !disallowedFields.some(isSet);
}
function isCityCountryOnly(vs) {
var isSet = (layer) => {
return vs.isset(`input:${layer}`);
};
var allowedFields = ['locality', 'country'];
var disallowedFields = ['query', 'category', 'housenumber', 'street',
'neighbourhood', 'borough', 'postcode', 'county', 'region'];
return allowedFields.every(isSet) &&
!disallowedFields.some(isSet);
}
function isPostalCodeOnly(vs) { function isPostalCodeOnly(vs) {
var isSet = (layer) => { var isSet = layer => vs.isset(`input:${layer}`);
return vs.isset(`input:${layer}`);
};
var allowedFields = ['postcode']; var allowedFields = ['postcode'];
var disallowedFields = ['query', 'category', 'housenumber', 'street', var disallowedFields = ['query', 'category', 'housenumber', 'street',

7
test/unit/query/search.js

@ -284,7 +284,7 @@ module.exports.tests.city_state = function(test, common) {
var query = generate(clean); var query = generate(clean);
t.notEqual(query, undefined, 'should not have returned undefined'); t.equal(query, undefined, 'should have returned undefined');
t.end(); t.end();
}); });
@ -300,7 +300,7 @@ module.exports.tests.city_state = function(test, common) {
var query = generate(clean); var query = generate(clean);
t.notEqual(query, undefined, 'should not have returned undefined'); t.equal(query, undefined, 'should have returned undefined');
t.end(); t.end();
}); });
@ -458,7 +458,7 @@ module.exports.tests.city_country = function(test, common) {
var query = generate(clean); var query = generate(clean);
t.notEqual(query, undefined, 'should not have returned undefined'); t.equal(query, undefined, 'should have returned undefined');
t.end(); t.end();
}); });
@ -621,7 +621,6 @@ module.exports.tests.city_country = function(test, common) {
t.end(); t.end();
}); });
}; };
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {

Loading…
Cancel
Save