[mod] new plugin: Autodetect search language

This commit is contained in:
ArtikusHG 2022-11-22 22:25:13 +02:00 committed by Markus Heiser
parent abb33bd7dd
commit 9925a20950
4 changed files with 21 additions and 0 deletions

View File

@ -16,3 +16,4 @@ setproctitle==1.3.2
redis==4.4.0 redis==4.4.0
markdown-it-py==2.1.0 markdown-it-py==2.1.0
typing_extensions==4.4.0 typing_extensions==4.4.0
fasttext==0.9.2

BIN
searx/data/lid.176.ftz Executable file

Binary file not shown.

View File

@ -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

View File

@ -196,6 +196,7 @@ outgoing:
# - 'Open Access DOI rewrite' # - 'Open Access DOI rewrite'
# - 'Vim-like hotkeys' # - 'Vim-like hotkeys'
# - 'Tor check plugin' # - 'Tor check plugin'
# - 'Autodetect search language'
# Configuration of the "Hostname replace" plugin: # Configuration of the "Hostname replace" plugin:
# #