diff --git a/app/configurations/config.default.js b/app/configurations/config.default.js index 0d814af682..d2f65c6005 100644 --- a/app/configurations/config.default.js +++ b/app/configurations/config.default.js @@ -67,6 +67,7 @@ export default { peliasMapping: {}, peliasLayer: null, peliasLocalization: null, + minimalRegexp: new RegExp('.{3,}'), }, nearbyRoutes: { diff --git a/app/configurations/waltti.js b/app/configurations/waltti.js index 303134e727..308a09b566 100644 --- a/app/configurations/waltti.js +++ b/app/configurations/waltti.js @@ -23,6 +23,10 @@ export default { showCityBikes: false, }, + search: { + minimalRegexp: new RegExp('.+'), + }, + agency: { show: false, }, diff --git a/app/util/searchUtils.js b/app/util/searchUtils.js index cc753cd919..54dc5b84e1 100644 --- a/app/util/searchUtils.js +++ b/app/util/searchUtils.js @@ -147,18 +147,29 @@ function getFavouriteLocations(favourites, input) { } export function getGeocodingResult( - text, + _text, searchParams, lang, focusPoint, sources, config, ) { - if (text === undefined || text === null || text.trim().length < 3) { + const text = _text ? _text.trim() : null; + if ( + text === undefined || + text === null || + text.length < 1 || + (config.search && + config.search.minimalRegexp && + !config.search.minimalRegexp.test(text)) + ) { return Promise.resolve([]); } - const opts = { text, ...searchParams, ...focusPoint, lang, sources }; + let opts = { text, ...searchParams, ...focusPoint, lang }; + if (sources) { + opts = { ...opts, sources }; + } return getJson(config.URL.PELIAS, opts) .then(res => @@ -371,16 +382,18 @@ export function executeSearchImmediate( .map(v => `gtfs${v}`) .join(','); - searchComponents.push( - getGeocodingResult( - input, - undefined, - language, - focusPoint, - sources, - config, - ), - ); + if (sources) { + searchComponents.push( + getGeocodingResult( + input, + undefined, + language, + focusPoint, + sources, + config, + ), + ); + } } endpointSearchesPromise = Promise.all(searchComponents)