diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 9b9e043c8..7270724b6 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -327,6 +327,7 @@ def _set_https_support_for_engine(engine): 'is_test': True, 'category': 'files', 'raise_for_status': True, + 'engine_data': {}, }) if 'url' not in params: diff --git a/searx/results.py b/searx/results.py index fb7e816eb..b3b874118 100644 --- a/searx/results.py +++ b/searx/results.py @@ -1,4 +1,5 @@ import re +from collections import defaultdict from operator import itemgetter from threading import RLock from urllib.parse import urlparse, unquote @@ -144,7 +145,7 @@ class ResultContainer: """docstring for ResultContainer""" __slots__ = '_merged_results', 'infoboxes', 'suggestions', 'answers', 'corrections', '_number_of_results',\ - '_ordered', 'paging', 'unresponsive_engines', 'timings', 'redirect_url' + '_ordered', 'paging', 'unresponsive_engines', 'timings', 'redirect_url', 'engine_data' def __init__(self): super().__init__() @@ -154,6 +155,7 @@ class ResultContainer: self.answers = {} self.corrections = set() self._number_of_results = [] + self.engine_data = defaultdict(dict) self._ordered = False self.paging = False self.unresponsive_engines = set() @@ -175,6 +177,8 @@ class ResultContainer: self._merge_infobox(result) elif 'number_of_results' in result: self._number_of_results.append(result['number_of_results']) + elif 'engine_data' in result: + self.engine_data[engine_name][result['key']] = result['engine_data'] else: # standard result (url, title, content) if 'url' in result and not isinstance(result['url'], str): diff --git a/searx/search/__init__.py b/searx/search/__init__.py index f777e8595..27c6c3a88 100644 --- a/searx/search/__init__.py +++ b/searx/search/__init__.py @@ -111,6 +111,8 @@ class Search: if request_params is None: continue + request_params['engine_data'] = self.search_query.engine_data.get(engineref.name, {}) + with threading.RLock(): processor.engine.stats['sent_search_count'] += 1 diff --git a/searx/search/models.py b/searx/search/models.py index 80ceaa223..21c0fe590 100644 --- a/searx/search/models.py +++ b/searx/search/models.py @@ -25,7 +25,7 @@ class SearchQuery: """container for all the search parameters (query, language, etc...)""" __slots__ = 'query', 'engineref_list', 'lang', 'safesearch', 'pageno', 'time_range',\ - 'timeout_limit', 'external_bang' + 'timeout_limit', 'external_bang', 'engine_data' def __init__(self, query: str, @@ -35,7 +35,8 @@ class SearchQuery: pageno: int=1, time_range: typing.Optional[str]=None, timeout_limit: typing.Optional[float]=None, - external_bang: typing.Optional[str]=None): + external_bang: typing.Optional[str]=None, + engine_data: typing.Optional[dict]=None): self.query = query self.engineref_list = engineref_list self.lang = lang @@ -44,6 +45,9 @@ class SearchQuery: self.time_range = time_range self.timeout_limit = timeout_limit self.external_bang = external_bang + self.engine_data = engine_data + if engine_data is None: + self.engine_data = {} @property def categories(self): diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html index eada8cd26..df2d42430 100644 --- a/searx/templates/oscar/results.html +++ b/searx/templates/oscar/results.html @@ -7,6 +7,13 @@ {{- "" -}} {% if timeout_limit %}{% endif -%} {%- endmacro %} +{% macro engine_data_form(engine_data) -%} + {% for engine_name, kv_data in engine_data.items() %} + {% for k, v in kv_data.items() %} + + {% endfor %} + {% endfor %} +{%- endmacro %} {%- macro search_url() %}{{ url_for('search', _external=True) }}?q={{ q|urlencode }}{% if selected_categories %}&categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&pageno={{ pageno }}{% endif %}{% if time_range %}&time_range={{ time_range }}{% endif %}{% if current_language != 'all' %}&language={{ current_language }}{% endif %}{% endmacro -%} {% block title %}{{ q|e }} - {% endblock %} @@ -142,12 +149,14 @@