Skip to content

Commit

Permalink
Merge pull request #1826 from HSLdevcom/one-char-search
Browse files Browse the repository at this point in the history
Activate search from first character
  • Loading branch information
siren authored Oct 3, 2017
2 parents b30feff + f96ef76 commit 1fb2918
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/configurations/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
peliasMapping: {},
peliasLayer: null,
peliasLocalization: null,
minimalRegexp: new RegExp('.{3,}'),
},

nearbyRoutes: {
Expand Down
4 changes: 4 additions & 0 deletions app/configurations/waltti.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default {
showCityBikes: false,
},

search: {
minimalRegexp: new RegExp('.+'),
},

agency: {
show: false,
},
Expand Down
39 changes: 26 additions & 13 deletions app/util/searchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1fb2918

Please sign in to comment.