.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
online_dictionary.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Processors for engine-type: ``online_dictionary``
3
4"""
5
6import re
7
8from searx.utils import is_valid_lang
9from .online import OnlineProcessor
10
11parser_re = re.compile('.*?([a-z]+)-([a-z]+) (.+)$', re.I)
12
13
15 """Processor class used by ``online_dictionary`` engines."""
16
17 engine_type = 'online_dictionary'
18
19 def get_params(self, search_query, engine_category):
20 """Returns a set of :ref:`request params <engine request online_dictionary>` or
21 ``None`` if search query does not match to :py:obj:`parser_re`.
22 """
23 params = super().get_params(search_query, engine_category)
24 if params is None:
25 return None
26
27 m = parser_re.match(search_query.query)
28 if not m:
29 return None
30
31 from_lang, to_lang, query = m.groups()
32
33 from_lang = is_valid_lang(from_lang)
34 to_lang = is_valid_lang(to_lang)
35
36 if not from_lang or not to_lang:
37 return None
38
39 params['from_lang'] = from_lang
40 params['to_lang'] = to_lang
41 params['query'] = query
42
43 return params
44
46 tests = {}
47
48 if getattr(self.engineengineengine, 'paging', False):
49 tests['translation_paging'] = {
50 'matrix': {'query': 'en-es house', 'pageno': (1, 2, 3)},
51 'result_container': ['not_empty', ('one_title_contains', 'house')],
52 'test': ['unique_results'],
53 }
54 else:
55 tests['translation'] = {
56 'matrix': {'query': 'en-es house'},
57 'result_container': ['not_empty', ('one_title_contains', 'house')],
58 }
59
60 return tests