|
|
@ -1,7 +1,8 @@ |
|
|
|
var peliasQuery = require('pelias-query'), |
|
|
|
var peliasQuery = require('pelias-query'), |
|
|
|
defaults = require('./search_defaults'), |
|
|
|
defaults = require('./search_defaults'), |
|
|
|
textParser = require('./text_parser'), |
|
|
|
textParser = require('./text_parser'), |
|
|
|
check = require('check-types'); |
|
|
|
check = require('check-types'), |
|
|
|
|
|
|
|
_ = require('lodash'); |
|
|
|
|
|
|
|
|
|
|
|
//------------------------------
|
|
|
|
//------------------------------
|
|
|
|
// general-purpose search query
|
|
|
|
// general-purpose search query
|
|
|
@ -120,7 +121,7 @@ function generateQuery( clean ){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getQuery(vs) { |
|
|
|
function getQuery(vs) { |
|
|
|
if (hasStreet(vs)) { |
|
|
|
if (hasStreet(vs) || isCityStateOnly(vs)) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
type: 'fallback', |
|
|
|
type: 'fallback', |
|
|
|
body: fallbackQuery.render(vs) |
|
|
|
body: fallbackQuery.render(vs) |
|
|
@ -137,4 +138,17 @@ function hasStreet(vs) { |
|
|
|
return vs.isset('input:street'); |
|
|
|
return vs.isset('input:street'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isCityStateOnly(vs) { |
|
|
|
|
|
|
|
var isSet = function(layer) { |
|
|
|
|
|
|
|
return vs.isset('input:' + layer); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var allowedFields = ['locality', 'region']; |
|
|
|
|
|
|
|
var disallowedFields = ['query', 'category', 'housenumber', 'street', |
|
|
|
|
|
|
|
'neighbourhood', 'borough', 'postcode', 'county', 'country']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return allowedFields.every(isSet) && !disallowedFields.some(isSet); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = generateQuery; |
|
|
|
module.exports = generateQuery; |
|
|
|