summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-22 15:51:26 +0100
committerMartin Fischer <martin@push-f.com>2022-01-03 07:01:49 +0100
commit8e9ad1ccc296c220d61f12926c94d98baa83e3ca (patch)
tree5ba40ba51b65c5fae48c4b008ebe85d0563b7466 /searx/engines/__init__.py
parent02e9bdf7550b5f5545bd842b24b71680960dd7a7 (diff)
downloadsearxng-8e9ad1ccc296c220d61f12926c94d98baa83e3ca.tar.gz
searxng-8e9ad1ccc296c220d61f12926c94d98baa83e3ca.zip
[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.
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py24
1 files changed, 24 insertions, 0 deletions
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,
+ )
+ ]