From df34b1ddcf02651ea0eae273baca6f340caad84e Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 22 Dec 2021 09:13:23 +0100 Subject: [enh] settings.yml: allow granular overwrites for about --- searx/engines/__init__.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'searx/engines') diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index a3dd7a95a..1fc01600a 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -138,6 +138,8 @@ def update_engine_attributes(engine, engine_data): if isinstance(param_value, str): param_value = list(map(str.strip, param_value.split(','))) engine.categories = param_value + elif hasattr(engine, 'about') and param_name == 'about': + engine.about = {**engine.about, **engine_data['about']} else: setattr(engine, param_name, param_value) -- cgit v1.2.3 From 8e9ad1ccc296c220d61f12926c94d98baa83e3ca Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 22 Dec 2021 15:51:26 +0100 Subject: [enh] introduce categories_as_tabs Previously all categories were displayed as search engine tabs. This commit changes that so that only the categories listed under categories_as_tabs in settings.yml are displayed. This lets us introduce more categories without cluttering up the UI. Categories not displayed as tabs can still be searched with !bangs. --- searx/engines/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'searx/engines') diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 1fc01600a..8d49bae8a 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -13,6 +13,7 @@ usage:: import sys import copy +import itertools from os.path import realpath, dirname from babel.localedata import locale_identifiers @@ -260,3 +261,26 @@ def load_engines(engine_list): if engine: register_engine(engine) return engines + + +DEFAULT_GROUP_NAME = 'others' + + +def group_engines_in_tab(engines): # pylint: disable=redefined-outer-name + def engine_sort_key(engine): + return (engine.about.get('language', ''), engine.name) + + def group_sort_key(group): + return (group[0] == DEFAULT_GROUP_NAME, group[0].lower()) + + def get_group(eng): + non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs']] + return non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME + + return [ + (groupname, sorted(engines, key=engine_sort_key)) + for groupname, engines in sorted( + ((name, list(engines)) for name, engines in itertools.groupby(sorted(engines, key=get_group), get_group)), + key=group_sort_key, + ) + ] -- cgit v1.2.3 From b02f762687c117baba523cefdcd16d0f94ae886a Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 22 Dec 2021 16:58:52 +0100 Subject: [enh] add more categories --- searx/engines/apkmirror.py | 2 +- searx/engines/archlinux.py | 2 +- searx/engines/bing.py | 2 +- searx/engines/bing_images.py | 2 +- searx/engines/bing_videos.py | 2 +- searx/engines/duckduckgo.py | 2 +- searx/engines/duckduckgo_images.py | 2 +- searx/engines/duden.py | 2 +- searx/engines/etools.py | 2 +- searx/engines/fdroid.py | 2 +- searx/engines/genius.py | 2 +- searx/engines/gentoo.py | 2 +- searx/engines/gigablast.py | 2 +- searx/engines/github.py | 2 +- searx/engines/google.py | 2 +- searx/engines/google_images.py | 2 +- searx/engines/google_videos.py | 2 +- searx/engines/seznam.py | 1 + searx/engines/sjp.py | 2 +- searx/engines/startpage.py | 2 +- searx/engines/translated.py | 2 +- searx/engines/yahoo.py | 2 +- 22 files changed, 22 insertions(+), 21 deletions(-) (limited to 'searx/engines') diff --git a/searx/engines/apkmirror.py b/searx/engines/apkmirror.py index da84bc79e..ac7cd7431 100644 --- a/searx/engines/apkmirror.py +++ b/searx/engines/apkmirror.py @@ -24,7 +24,7 @@ about = { } # engine dependent config -categories = ['files'] +categories = ['files', 'apps'] paging = True time_range_support = False diff --git a/searx/engines/archlinux.py b/searx/engines/archlinux.py index 1cfb3983f..b5e426107 100644 --- a/searx/engines/archlinux.py +++ b/searx/engines/archlinux.py @@ -20,7 +20,7 @@ about = { } # engine dependent config -categories = ['it'] +categories = ['it', 'software wikis'] paging = True base_url = 'https://wiki.archlinux.org' diff --git a/searx/engines/bing.py b/searx/engines/bing.py index 1170227ad..9744b1800 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -20,7 +20,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] paging = True time_range_support = False safesearch = False diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py index f07d07144..cb69dc172 100644 --- a/searx/engines/bing_images.py +++ b/searx/engines/bing_images.py @@ -27,7 +27,7 @@ about = { } # engine dependent config -categories = ['images'] +categories = ['images', 'web'] paging = True safesearch = True time_range_support = True diff --git a/searx/engines/bing_videos.py b/searx/engines/bing_videos.py index 184f564df..ae8e8d49a 100644 --- a/searx/engines/bing_videos.py +++ b/searx/engines/bing_videos.py @@ -26,7 +26,7 @@ about = { "results": 'HTML', } -categories = ['videos'] +categories = ['videos', 'web'] paging = True safesearch = True time_range_support = True diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index 0d2a524df..71da72677 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -27,7 +27,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] paging = True supported_languages_url = 'https://duckduckgo.com/util/u588.js' time_range_support = True diff --git a/searx/engines/duckduckgo_images.py b/searx/engines/duckduckgo_images.py index 2f75e16f1..7d844b543 100644 --- a/searx/engines/duckduckgo_images.py +++ b/searx/engines/duckduckgo_images.py @@ -27,7 +27,7 @@ about = { } # engine dependent config -categories = ['images'] +categories = ['images', 'web'] paging = True safesearch = True diff --git a/searx/engines/duden.py b/searx/engines/duden.py index 600b61f3c..090295b91 100644 --- a/searx/engines/duden.py +++ b/searx/engines/duden.py @@ -19,7 +19,7 @@ about = { "language": 'de', } -categories = ['general'] +categories = ['general', 'dictionaries'] paging = True # search-url diff --git a/searx/engines/etools.py b/searx/engines/etools.py index 347463291..08bc63cd8 100644 --- a/searx/engines/etools.py +++ b/searx/engines/etools.py @@ -17,7 +17,7 @@ about = { "results": 'HTML', } -categories = ['general'] +categories = ['general', 'web'] paging = False safesearch = True diff --git a/searx/engines/fdroid.py b/searx/engines/fdroid.py index c381b25d4..b5f004e7b 100644 --- a/searx/engines/fdroid.py +++ b/searx/engines/fdroid.py @@ -18,7 +18,7 @@ about = { } # engine dependent config -categories = ['files'] +categories = ['files', 'apps'] paging = True # search-url diff --git a/searx/engines/genius.py b/searx/engines/genius.py index b0fcb09a8..1f4b4b03e 100644 --- a/searx/engines/genius.py +++ b/searx/engines/genius.py @@ -20,7 +20,7 @@ about = { } # engine dependent config -categories = ['music'] +categories = ['music', 'lyrics'] paging = True page_size = 5 diff --git a/searx/engines/gentoo.py b/searx/engines/gentoo.py index 5b9edafe0..856c93710 100644 --- a/searx/engines/gentoo.py +++ b/searx/engines/gentoo.py @@ -18,7 +18,7 @@ about = { } # engine dependent config -categories = ['it'] +categories = ['it', 'software wikis'] paging = True base_url = 'https://wiki.gentoo.org' diff --git a/searx/engines/gigablast.py b/searx/engines/gigablast.py index c657dca30..1c40ff331 100644 --- a/searx/engines/gigablast.py +++ b/searx/engines/gigablast.py @@ -22,7 +22,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] # gigablast's pagination is totally damaged, don't use it paging = False safesearch = True diff --git a/searx/engines/github.py b/searx/engines/github.py index 1d12d296a..343f3793d 100644 --- a/searx/engines/github.py +++ b/searx/engines/github.py @@ -17,7 +17,7 @@ about = { } # engine dependent config -categories = ['it'] +categories = ['it', 'repos'] # search-url search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa diff --git a/searx/engines/google.py b/searx/engines/google.py index 685697d29..ed4381f47 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -41,7 +41,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] paging = True time_range_support = True safesearch = True diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py index 203df404a..2855860d8 100644 --- a/searx/engines/google_images.py +++ b/searx/engines/google_images.py @@ -45,7 +45,7 @@ about = { } # engine dependent config -categories = ['images'] +categories = ['images', 'web'] paging = False use_locale_domain = True time_range_support = True diff --git a/searx/engines/google_videos.py b/searx/engines/google_videos.py index 049f9138c..06aac8ae1 100644 --- a/searx/engines/google_videos.py +++ b/searx/engines/google_videos.py @@ -54,7 +54,7 @@ about = { # engine dependent config -categories = ['videos'] +categories = ['videos', 'web'] paging = False language_support = True use_locale_domain = True diff --git a/searx/engines/seznam.py b/searx/engines/seznam.py index 2e95b4769..48a167ce0 100644 --- a/searx/engines/seznam.py +++ b/searx/engines/seznam.py @@ -25,6 +25,7 @@ about = { "language": "cz", } +categories = ['general', 'web'] base_url = 'https://search.seznam.cz/' diff --git a/searx/engines/sjp.py b/searx/engines/sjp.py index ad498b847..97a81d8a7 100644 --- a/searx/engines/sjp.py +++ b/searx/engines/sjp.py @@ -21,7 +21,7 @@ about = { "language": 'pl', } -categories = ['general'] +categories = ['general', 'dictionaries'] paging = False URL = 'https://sjp.pwn.pl' diff --git a/searx/engines/startpage.py b/searx/engines/startpage.py index 65d90debe..97891921c 100644 --- a/searx/engines/startpage.py +++ b/searx/engines/startpage.py @@ -23,7 +23,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] # there is a mechanism to block "bot" search # (probably the parameter qid), require # storing of qid's between mulitble search-calls diff --git a/searx/engines/translated.py b/searx/engines/translated.py index 62ade49e2..6cc56328b 100644 --- a/searx/engines/translated.py +++ b/searx/engines/translated.py @@ -14,7 +14,7 @@ about = { } engine_type = 'online_dictionary' -categories = ['general'] +categories = ['general', 'dictionaries'] url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}' web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}' weight = 100 diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py index 08bde6665..6bf1932e4 100644 --- a/searx/engines/yahoo.py +++ b/searx/engines/yahoo.py @@ -31,7 +31,7 @@ about = { } # engine dependent config -categories = ['general'] +categories = ['general', 'web'] paging = True time_range_support = True supported_languages_url = 'https://search.yahoo.com/preferences/languages' -- cgit v1.2.3 From ab90e2ac49778153409397d4a2c34e9051963a0f Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 28 Dec 2021 16:12:54 +0100 Subject: [enh] show categories not in any tab category in "Other" preferences tab Previously we didn't have a good place to put search engines that don't fit into any of the tab categories. This commit automatically puts search engines that don't belong to any tab category in an "other" category, that is only displayed in the user preferences (and not above search results). --- searx/engines/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'searx/engines') diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 8d49bae8a..9472186bf 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -45,6 +45,9 @@ ENGINE_DEFAULT_ARGS = { "display_error_messages": True, "tokens": [], } +# set automatically when an engine does not have any tab category +OTHER_CATEGORY = 'other' + """Defaults for the namespace of an engine module, see :py:func:`load_engine`""" categories = {'general': []} @@ -114,6 +117,9 @@ def load_engine(engine_data): set_loggers(engine, engine_name) + if not any(cat in settings['categories_as_tabs'] for cat in engine.categories): + engine.categories.append(OTHER_CATEGORY) + return engine @@ -274,7 +280,7 @@ def group_engines_in_tab(engines): # pylint: disable=redefined-outer-name return (group[0] == DEFAULT_GROUP_NAME, group[0].lower()) def get_group(eng): - non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs']] + non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs'] + [OTHER_CATEGORY]] return non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME return [ -- cgit v1.2.3 From 5d74bf382012c73c701e1a4969e0f420b099db9f Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 28 Dec 2021 16:26:38 +0100 Subject: [enh] move dictionaries, Erowid & IMDb out of general category The general category is the category that is searched by default. From a privacy standpoint it doesn't make sense to send all general queries to specialized search engines that cannot deal with those queries anyway. --- searx/engines/duden.py | 2 +- searx/engines/imdb.py | 4 +--- searx/engines/sjp.py | 2 +- searx/engines/translated.py | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'searx/engines') diff --git a/searx/engines/duden.py b/searx/engines/duden.py index 090295b91..da4c4f7da 100644 --- a/searx/engines/duden.py +++ b/searx/engines/duden.py @@ -19,7 +19,7 @@ about = { "language": 'de', } -categories = ['general', 'dictionaries'] +categories = ['dictionaries'] paging = True # search-url diff --git a/searx/engines/imdb.py b/searx/engines/imdb.py index bb6258cf4..0897b8dca 100644 --- a/searx/engines/imdb.py +++ b/searx/engines/imdb.py @@ -27,9 +27,7 @@ about = { "results": 'HTML', } -categories = [ - 'general', -] +categories = [] paging = False # suggestion_url = "https://sg.media-imdb.com/suggestion/{letter}/{query}.json" diff --git a/searx/engines/sjp.py b/searx/engines/sjp.py index 97a81d8a7..8342a2819 100644 --- a/searx/engines/sjp.py +++ b/searx/engines/sjp.py @@ -21,7 +21,7 @@ about = { "language": 'pl', } -categories = ['general', 'dictionaries'] +categories = ['dictionaries'] paging = False URL = 'https://sjp.pwn.pl' diff --git a/searx/engines/translated.py b/searx/engines/translated.py index 6cc56328b..9900c017b 100644 --- a/searx/engines/translated.py +++ b/searx/engines/translated.py @@ -14,7 +14,7 @@ about = { } engine_type = 'online_dictionary' -categories = ['general', 'dictionaries'] +categories = ['dictionaries'] url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}' web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}' weight = 100 -- cgit v1.2.3 From 1e195f5b95d4c59105249d66f5d170d40139a461 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 3 Jan 2022 07:24:20 +0100 Subject: [mod] move group_engines_in_tab to searx.webutils --- searx/engines/__init__.py | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'searx/engines') diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 9472186bf..70f6281a6 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -13,7 +13,6 @@ usage:: import sys import copy -import itertools from os.path import realpath, dirname from babel.localedata import locale_identifiers @@ -267,26 +266,3 @@ def load_engines(engine_list): if engine: register_engine(engine) return engines - - -DEFAULT_GROUP_NAME = 'others' - - -def group_engines_in_tab(engines): # pylint: disable=redefined-outer-name - def engine_sort_key(engine): - return (engine.about.get('language', ''), engine.name) - - def group_sort_key(group): - return (group[0] == DEFAULT_GROUP_NAME, group[0].lower()) - - def get_group(eng): - non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs'] + [OTHER_CATEGORY]] - return non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME - - return [ - (groupname, sorted(engines, key=engine_sort_key)) - for groupname, engines in sorted( - ((name, list(engines)) for name, engines in itertools.groupby(sorted(engines, key=get_group), get_group)), - key=group_sort_key, - ) - ] -- cgit v1.2.3 From d01e8aa8ccee9b3f1a8705cd4b0c67c012d0b06c Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 4 Jan 2022 15:28:05 +0100 Subject: [mod] introduce searx.engines.Engine for type hinting --- searx/engines/__init__.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'searx/engines') diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 70f6281a6..7e8336e01 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -13,6 +13,7 @@ usage:: import sys import copy +from typing import List from os.path import realpath, dirname from babel.localedata import locale_identifiers @@ -47,7 +48,26 @@ ENGINE_DEFAULT_ARGS = { # set automatically when an engine does not have any tab category OTHER_CATEGORY = 'other' -"""Defaults for the namespace of an engine module, see :py:func:`load_engine`""" + +class Engine: # pylint: disable=too-few-public-methods + """This class is currently never initialized and only used for type hinting.""" + + name: str + engine: str + shortcut: str + categories: List[str] + supported_languages: List[str] + about: dict + inactive: bool + disabled: bool + language_support: bool + paging: bool + safesearch: bool + time_range_support: bool + timeout: float + + +# Defaults for the namespace of an engine module, see :py:func:`load_engine`` categories = {'general': []} engines = {} -- cgit v1.2.3