mirror of
https://github.com/searxng/searxng.git
synced 2025-07-24 13:49:26 +02:00
[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>
This commit is contained in:
parent
f46d0584ef
commit
2ffd446e5c
8 changed files with 26 additions and 28 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue