diff options
Diffstat (limited to 'searx/search')
| -rw-r--r-- | searx/search/__init__.py | 5 | ||||
| -rw-r--r-- | searx/search/checker/background.py | 2 | ||||
| -rw-r--r-- | searx/search/models.py | 9 | ||||
| -rw-r--r-- | searx/search/processors/abstract.py | 7 | ||||
| -rw-r--r-- | searx/search/processors/online.py | 16 | ||||
| -rw-r--r-- | searx/search/processors/online_currency.py | 3 | ||||
| -rw-r--r-- | searx/search/processors/online_dictionary.py | 4 | ||||
| -rw-r--r-- | searx/search/processors/online_url_search.py | 3 |
8 files changed, 45 insertions, 4 deletions
diff --git a/searx/search/__init__.py b/searx/search/__init__.py index c517814de..9d337916c 100644 --- a/searx/search/__init__.py +++ b/searx/search/__init__.py @@ -2,11 +2,12 @@ # lint: pylint # pylint: disable=missing-module-docstring, too-few-public-methods -import typing import threading from timeit import default_timer from uuid import uuid4 +import flask + from searx import settings from searx.answerers import ask from searx.external_bang import get_bang_url @@ -181,7 +182,7 @@ class SearchWithPlugins(Search): __slots__ = 'ordered_plugin_list', 'request' - def __init__(self, search_query: SearchQuery, ordered_plugin_list, request: "flask.Request"): + def __init__(self, search_query: SearchQuery, ordered_plugin_list, request: flask.Request): super().__init__(search_query) self.ordered_plugin_list = ordered_plugin_list self.result_container.on_result = self._on_result diff --git a/searx/search/checker/background.py b/searx/search/checker/background.py index f47e7d752..f8dfed4fa 100644 --- a/searx/search/checker/background.py +++ b/searx/search/checker/background.py @@ -16,7 +16,7 @@ from searx import logger, settings, searx_debug from searx.exceptions import SearxSettingsException from searx.search.processors import PROCESSORS from searx.search.checker import Checker -from searx.shared import schedule, storage +from searx.shared import schedule, storage # pyright: ignore CHECKER_RESULT = 'CHECKER_RESULT' diff --git a/searx/search/models.py b/searx/search/models.py index ff5897966..bbca1cd1d 100644 --- a/searx/search/models.py +++ b/searx/search/models.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: AGPL-3.0-or-later import typing +import babel class EngineRef: @@ -29,6 +30,7 @@ class SearchQuery: 'query', 'engineref_list', 'lang', + 'locale', 'safesearch', 'pageno', 'time_range', @@ -59,6 +61,13 @@ class SearchQuery: self.external_bang = external_bang self.engine_data = engine_data or {} + self.locale = None + if self.lang: + try: + self.locale = babel.Locale.parse(self.lang, sep='-') + except babel.core.UnknownLocaleError: + pass + @property def categories(self): return list(set(map(lambda engineref: engineref.category, self.engineref_list))) diff --git a/searx/search/processors/abstract.py b/searx/search/processors/abstract.py index d4822fc56..d74616db0 100644 --- a/searx/search/processors/abstract.py +++ b/searx/search/processors/abstract.py @@ -138,6 +138,13 @@ class EngineProcessor(ABC): return False def get_params(self, search_query, engine_category): + """Returns a set of *request params* or ``None`` if request is not supported. + + Not supported conditions (``None`` is returned): + + - A page-number > 1 when engine does not support paging. + - A time range when the engine does not support time range. + """ # if paging is not supported, skip if search_query.pageno > 1 and not self.engine.paging: return None diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py index 8d8275df1..17e9b6a96 100644 --- a/searx/search/processors/online.py +++ b/searx/search/processors/online.py @@ -60,6 +60,17 @@ class OnlineProcessor(EngineProcessor): # add an user agent params['headers']['User-Agent'] = gen_useragent() + # add Accept-Language header + if self.engine.send_accept_language_header and search_query.locale: + ac_lang = search_query.locale.language + if search_query.locale.territory: + ac_lang = "%s-%s,%s;q=0.9,*;q=0.5" % ( + search_query.locale.language, + search_query.locale.territory, + search_query.locale.language, + ) + params['headers']['Accept-Language'] = ac_lang + return params def _send_http_request(self, params): @@ -162,6 +173,11 @@ class OnlineProcessor(EngineProcessor): self.handle_exception(result_container, e, suspend=True) self.logger.exception('CAPTCHA') except SearxEngineTooManyRequestsException as e: + if "google" in self.engine_name: + self.logger.warn( + "Set to 'true' the use_mobile_ui parameter in the 'engines:'" + " section of your settings.yml file if google is blocked for you." + ) self.handle_exception(result_container, e, suspend=True) self.logger.exception('Too many requests') except SearxEngineAccessDeniedException as e: diff --git a/searx/search/processors/online_currency.py b/searx/search/processors/online_currency.py index 6bd891b1d..92398239f 100644 --- a/searx/search/processors/online_currency.py +++ b/searx/search/processors/online_currency.py @@ -38,6 +38,9 @@ class OnlineCurrencyProcessor(OnlineProcessor): engine_type = 'online_currency' def get_params(self, search_query, engine_category): + """Returns a set of *request params* or ``None`` if search query does not match + to :py:obj:`parser_re`.""" + params = super().get_params(search_query, engine_category) if params is None: return None diff --git a/searx/search/processors/online_dictionary.py b/searx/search/processors/online_dictionary.py index 3e7f6ed59..fbfc9df8e 100644 --- a/searx/search/processors/online_dictionary.py +++ b/searx/search/processors/online_dictionary.py @@ -9,7 +9,7 @@ import re from searx.utils import is_valid_lang from .online import OnlineProcessor -parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I) +parser_re = re.compile('.*?([a-z]+)-([a-z]+) (.+)$', re.I) class OnlineDictionaryProcessor(OnlineProcessor): @@ -18,6 +18,8 @@ class OnlineDictionaryProcessor(OnlineProcessor): engine_type = 'online_dictionary' def get_params(self, search_query, engine_category): + """Returns a set of *request params* or ``None`` if search query does not match + to :py:obj:`parser_re`.""" params = super().get_params(search_query, engine_category) if params is None: return None diff --git a/searx/search/processors/online_url_search.py b/searx/search/processors/online_url_search.py index 2863be28e..6383fa37f 100644 --- a/searx/search/processors/online_url_search.py +++ b/searx/search/processors/online_url_search.py @@ -20,6 +20,9 @@ class OnlineUrlSearchProcessor(OnlineProcessor): engine_type = 'online_url_search' def get_params(self, search_query, engine_category): + """Returns a set of *request params* or ``None`` if search query does not match + to at least one of :py:obj:`re_search_urls`. + """ params = super().get_params(search_query, engine_category) if params is None: return None |