From 1f8f8c1e91040fd10bacdc473b8d5f97dda6424e Mon Sep 17 00:00:00 2001 From: ArtikusHG Date: Sun, 11 Dec 2022 17:45:47 +0200 Subject: Replace langdetect with fasttext --- searx/search/checker/impl.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'searx/search') diff --git a/searx/search/checker/impl.py b/searx/search/checker/impl.py index 0705b6822..37f145e1e 100644 --- a/searx/search/checker/impl.py +++ b/searx/search/checker/impl.py @@ -10,12 +10,10 @@ from timeit import default_timer from urllib.parse import urlparse import re -from langdetect import detect_langs -from langdetect.lang_detect_exception import LangDetectException import httpx from searx import network, logger -from searx.utils import gen_useragent +from searx.utils import gen_useragent, detect_language from searx.results import ResultContainer from searx.search.models import SearchQuery, EngineRef from searx.search.processors import EngineProcessor @@ -208,14 +206,10 @@ class ResultContainerTests: self.test_results.add_error(self.test_name, message, *args, '(' + sqstr + ')') def _add_language(self, text: str) -> typing.Optional[str]: - try: - r = detect_langs(str(text)) # pylint: disable=E1101 - except LangDetectException: - return None - - if len(r) > 0 and r[0].prob > 0.95: - self.languages.add(r[0].lang) - self.test_results.add_language(r[0].lang) + langStr = detect_language(text) + if langStr: + self.languages.add(langStr) + self.test_results.add_language(langStr) return None def _check_result(self, result): -- cgit v1.2.3-54-g00ecf