diff options
author | ArtikusHG <artiomoleynic@gmail.com> | 2022-11-22 22:25:13 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-12-10 13:11:47 +0100 |
commit | 9925a209503cc41e37a1c032548a5fd8fd8ea362 (patch) | |
tree | fe2a5bb74228aa6d77b56becf3091a595b79d01c /searx/plugins | |
parent | abb33bd7ddf913fd98826584ed8b687889d3b346 (diff) | |
download | searxng-9925a209503cc41e37a1c032548a5fd8fd8ea362.tar.gz searxng-9925a209503cc41e37a1c032548a5fd8fd8ea362.zip |
[mod] new plugin: Autodetect search language
Diffstat (limited to 'searx/plugins')
-rw-r--r-- | searx/plugins/autodetect_search_language.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/searx/plugins/autodetect_search_language.py b/searx/plugins/autodetect_search_language.py new file mode 100644 index 000000000..3bcb80098 --- /dev/null +++ b/searx/plugins/autodetect_search_language.py @@ -0,0 +1,19 @@ +import fasttext +import os +from flask_babel import gettext + +name = gettext('Autodetect search language') +description = gettext('Automatically detect the query search language and switch to it.') +preference_section = 'general' +default_on = False + + +fasttext.FastText.eprint = lambda x: None +model = fasttext.load_model(os.path.dirname(os.path.realpath(__file__)) + '/../data/lid.176.ftz') + + +def pre_search(request, search): + lang = model.predict(search.search_query.query, k=1) + if lang[1][0] >= 0.3: + search.search_query.lang = lang[0][0].split('__label__')[1] + return True |