summaryrefslogtreecommitdiff
path: root/searx/webutils.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-07-24 09:32:05 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-04-07 11:03:25 +0200
commit2ffd446e5c0be30717d9ff112d34ef606f08fcdd (patch)
tree9a7f85ef11ca13a1092c75800f6a77df05357b62 /searx/webutils.py
parentf46d0584ef17a83e2c1089a11aa037ebb098ba57 (diff)
downloadsearxng-2ffd446e5c0be30717d9ff112d34ef606f08fcdd.tar.gz
searxng-2ffd446e5c0be30717d9ff112d34ef606f08fcdd.zip
[mod] clarify the difference of the default category and subgrouping
This PR does no functional change it is just an attempt to make more clear in the code, what a default category is and what a subcategory is. The previous name 'others' leads to confusion with the **category 'other'**. If a engine is not assigned to a category, the default is assigned:: DEFAULT_CATEGORY = 'other' If an engine has only one category and this category is shown as tab in the user interface, this engine has no further subgrouping:: NO_SUBGROUPING = 'without further subgrouping' Related: - https://github.com/searxng/searxng/issues/1604 - https://github.com/searxng/searxng/pull/1545 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webutils.py')
-rw-r--r--searx/webutils.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/searx/webutils.py b/searx/webutils.py
index e62b0d695..4b11a15af 100644
--- a/searx/webutils.py
+++ b/searx/webutils.py
@@ -18,7 +18,7 @@ from codecs import getincrementalencoder
from flask_babel import gettext, format_date
from searx import logger, settings
-from searx.engines import OTHER_CATEGORY
+from searx.engines import DEFAULT_CATEGORY
if TYPE_CHECKING:
from searx.enginelib import Engine
@@ -222,26 +222,24 @@ def is_flask_run_cmdline():
return frames[-2].filename.endswith('flask/cli.py')
-DEFAULT_GROUP_NAME = 'others'
+NO_SUBGROUPING = 'without further subgrouping'
def group_engines_in_tab(engines: Iterable[Engine]) -> List[Tuple[str, Iterable[Engine]]]:
- """Groups an Iterable of engines by their first non tab category"""
+ """Groups an Iterable of engines by their first non tab category (first subgroup)"""
- def get_group(eng):
- non_tab_categories = [
- c for c in eng.categories if c not in list(settings['categories_as_tabs'].keys()) + [OTHER_CATEGORY]
- ]
- return non_tab_categories[0] if len(non_tab_categories) > 0 else DEFAULT_GROUP_NAME
-
- groups = itertools.groupby(sorted(engines, key=get_group), get_group)
+ def get_subgroup(eng):
+ non_tab_categories = [c for c in eng.categories if c not in tabs + [DEFAULT_CATEGORY]]
+ return non_tab_categories[0] if len(non_tab_categories) > 0 else NO_SUBGROUPING
def group_sort_key(group):
- return (group[0] == DEFAULT_GROUP_NAME, group[0].lower())
-
- sorted_groups = sorted(((name, list(engines)) for name, engines in groups), key=group_sort_key)
+ return (group[0] == NO_SUBGROUPING, group[0].lower())
def engine_sort_key(engine):
return (engine.about.get('language', ''), engine.name)
+ tabs = list(settings['categories_as_tabs'].keys())
+ subgroups = itertools.groupby(sorted(engines, key=get_subgroup), get_subgroup)
+ sorted_groups = sorted(((name, list(engines)) for name, engines in subgroups), key=group_sort_key)
+
return [(groupname, sorted(engines, key=engine_sort_key)) for groupname, engines in sorted_groups]