From 7ec8bc3ea76516e33318c67165161df5c1efdd36 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 16 Dec 2020 13:41:32 +0100 Subject: [mod] split searx.search into different processors see searx.search.processors.abstract.EngineProcessor First the method searx call the get_params method. If the return value is not None, then the searx call the method search. --- searx/search/processors/online_dictionary.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 searx/search/processors/online_dictionary.py (limited to 'searx/search/processors/online_dictionary.py') diff --git a/searx/search/processors/online_dictionary.py b/searx/search/processors/online_dictionary.py new file mode 100644 index 000000000..8e9ef1620 --- /dev/null +++ b/searx/search/processors/online_dictionary.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +import re + +from searx.utils import is_valid_lang +from .online import OnlineProcessor + + +parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I) + + +class OnlineDictionaryProcessor(OnlineProcessor): + + engine_type = 'online_dictionnary' + + def get_params(self, search_query, engine_category): + params = super().get_params(search_query, engine_category) + if params is None: + return None + + m = parser_re.match(search_query.query) + if not m: + return None + + from_lang, to_lang, query = m.groups() + + from_lang = is_valid_lang(from_lang) + to_lang = is_valid_lang(to_lang) + + if not from_lang or not to_lang: + return None + + params['from_lang'] = from_lang + params['to_lang'] = to_lang + params['query'] = query + + return params -- cgit v1.2.3