From 444b1e70dbcfd258482b5ee258895593a0a2e42c Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 22 Apr 2022 13:47:54 +0200 Subject: [PATCH] [mod] add setting: search.autocomplete_min Minimun characters to type before autocompleter starts. Signed-off-by: Markus Heiser --- searx/settings.yml | 2 ++ searx/settings_defaults.py | 1 + searx/static/themes/simple/src/js/main/search.js | 2 +- searx/webapp.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/searx/settings.yml b/searx/settings.yml index 6e5556d0c..5aaf154df 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -18,6 +18,8 @@ search: # "seznam", "startpage", "swisscows", "qwant", "wikipedia" - leave blank to turn it off # by default. autocomplete: "" + # minimun characters to type before autocompleter starts + autocomplete_min: 4 # Default search language - leave blank to detect from browser information or # use codes from 'languages.py' default_lang: "" diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 7110fce93..938b9714d 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -153,6 +153,7 @@ SCHEMA = { 'search': { 'safe_search': SettingsValue((0, 1, 2), 0), 'autocomplete': SettingsValue(str, ''), + 'autocomplete_min': SettingsValue(int, 4), 'default_lang': SettingsValue(tuple(LANGUAGE_CODES + ['']), ''), 'languages': SettingSublistValue(LANGUAGE_CODES, LANGUAGE_CODES), 'ban_time_on_fail': SettingsValue(numbers.Real, 5), diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js index edd68d259..20e58e0fe 100644 --- a/searx/static/themes/simple/src/js/main/search.js +++ b/searx/static/themes/simple/src/js/main/search.js @@ -68,7 +68,7 @@ "Content-type": "application/x-www-form-urlencoded", "X-Requested-With": "XMLHttpRequest" }, - MinChars: 4, + MinChars: searxng.settings.autocomplete_min, Delay: 300, _Position: function () {}, _Open: function () { diff --git a/searx/webapp.py b/searx/webapp.py index b91e96df1..178500df6 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -449,6 +449,7 @@ def get_client_settings(): req_pref = request.preferences return { 'autocomplete_provider': req_pref.get_value('autocomplete'), + 'autocomplete_min' : get_setting('search.autocomplete_min'), 'http_method': req_pref.get_value('method'), 'infinite_scroll': req_pref.get_value('infinite_scroll'), 'translations': get_translations(),