From a361afeba39cc46bafd6e35c187cfced722f565b Mon Sep 17 00:00:00 2001 From: Lasse Liehu Date: Thu, 15 Jun 2023 07:56:47 +0300 Subject: [PATCH 1/2] Relax minimum char limit in location search Nominatim does not return prefix matches, so it could be good to even remove this minimum limit. However, searches with only a single Latin letter can take more than 1 second on Nominatim's end. So, perhaps it's good to first relax the global limit to 2 characters and have additional logic that there is no minimum limit if the input text contains characters from certain scripts. --- src/components/filters/location.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/filters/location.js b/src/components/filters/location.js index 4e78df6f..d71c45e0 100644 --- a/src/components/filters/location.js +++ b/src/components/filters/location.js @@ -149,7 +149,7 @@ export class LocationSelect extends React.PureComponent { }; getAsyncOptions = (input: string, cb: (e: ?Error, any) => void) => { - if (input.length >= 3) { + if (input.length >= 2) { return nominatimSearch(input, this.state.queryType) .then(json => { if (!Array.isArray(json)) return cb(null, { options: [] }); From 13a4e4f31a690767fc5c8f1c61de403495b9a9b1 Mon Sep 17 00:00:00 2001 From: Lasse Liehu Date: Sat, 24 Jun 2023 20:41:26 +0300 Subject: [PATCH 2/2] Improve minimum char limit in location search Make the minimum limit depend on the input characters. No limit is used if the input contains characters that are used in the following CJK scripts: Han, Hangul, Hiragana and Katakana. These scripts were chosen because there are place names that can be written with 1 character in Han, Hiragana and Katakana. In Hangul, it looks possible that such place names exist and often an input method similar to the other scripts is used, which reduces the probability of triggering search with only 1 character when the user has not yet finished typing. New scripts can be added to the regular expression with a similar reasoning. `scx` is used in the regular expression because `Script_Extensions` is a more useful property than `Script` when a single Unicode character can be used in multiple scripts. It would be even simpler to just remove the limit completely because Nominatim does not return prefix matches. However, at least queries that contain only 1 Latin letter take longer than queries with at least a few characters. Also, the component that displays the results seems to have some kind of problem displaying the results for the subsequent queries and this problem might become more apparent for more users if the character limit is removed. --- src/components/filters/location.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/filters/location.js b/src/components/filters/location.js index d71c45e0..da96bdfb 100644 --- a/src/components/filters/location.js +++ b/src/components/filters/location.js @@ -149,7 +149,7 @@ export class LocationSelect extends React.PureComponent { }; getAsyncOptions = (input: string, cb: (e: ?Error, any) => void) => { - if (input.length >= 2) { + if (input.length >= 2 || this.isOneCharInputAllowed(input)) { return nominatimSearch(input, this.state.queryType) .then(json => { if (!Array.isArray(json)) return cb(null, { options: [] }); @@ -165,6 +165,18 @@ export class LocationSelect extends React.PureComponent { return cb(null, { options: [] }); } }; + isOneCharInputAllowed = (input: string) => { + // Allowing one character input if it contains characters from certain scripts while + // guarding against browsers that don't support this kind of regular expression + try { + return /\p{scx=Han}|\p{scx=Hangul}|\p{scx=Hiragana}|\p{scx=Katakana}/u.test( + input + ); + } catch { + // Allowing always is better than never allowing for the above-mentioned scripts + return true; + } + }; onChangeLocal = (data: ?Array) => { if (data) { this.draw.deleteAll();