コード例 #1
0
ファイル: webapp.py プロジェクト: neonecosystem/searx
def config():
    return jsonify({
        'categories':
        categories.keys(),
        'engines': [{
            'name': engine_name,
            'categories': engine.categories,
            'shortcut': engine.shortcut,
            'enabled': not engine.disabled
        } for engine_name, engine in engines.items()],
        'plugins': [{
            'name': plugin.name,
            'enabled': plugin.default_on
        } for plugin in plugins],
        'instance_name':
        settings['general']['instance_name'],
        'locales':
        settings['locales'],
        'default_locale':
        settings['ui']['default_locale'],
        'autocomplete':
        settings['search']['autocomplete'],
        'safe_search':
        settings['search']['safe_search'],
        'default_theme':
        settings['ui']['default_theme'],
        'version':
        VERSION_STRING
    })
コード例 #2
0
ファイル: webapp.py プロジェクト: asciimoo/searx
def config():
    return jsonify({'categories': categories.keys(),
                    'engines': [{'name': engine_name,
                                 'categories': engine.categories,
                                 'shortcut': engine.shortcut,
                                 'enabled': not engine.disabled,
                                 'paging': engine.paging,
                                 'language_support': engine.language_support,
                                 'supported_languages':
                                 engine.supported_languages.keys()
                                 if isinstance(engine.supported_languages, dict)
                                 else engine.supported_languages,
                                 'safesearch': engine.safesearch,
                                 'time_range_support': engine.time_range_support,
                                 'timeout': engine.timeout}
                                for engine_name, engine in engines.items()],
                    'plugins': [{'name': plugin.name,
                                 'enabled': plugin.default_on}
                                for plugin in plugins],
                    'instance_name': settings['general']['instance_name'],
                    'locales': settings['locales'],
                    'default_locale': settings['ui']['default_locale'],
                    'autocomplete': settings['search']['autocomplete'],
                    'safe_search': settings['search']['safe_search'],
                    'default_theme': settings['ui']['default_theme'],
                    'version': VERSION_STRING,
                    'doi_resolvers': [r for r in settings['doi_resolvers']],
                    'default_doi_resolver': settings['default_doi_resolver'],
                    })
コード例 #3
0
ファイル: webapp.py プロジェクト: yomguy/searx
def config():
    return jsonify({'categories': list(categories.keys()),
                    'engines': [{'name': name,
                                 'categories': engine.categories,
                                 'shortcut': engine.shortcut,
                                 'enabled': not engine.disabled,
                                 'paging': engine.paging,
                                 'language_support': engine.language_support,
                                 'supported_languages':
                                 list(engine.supported_languages.keys())
                                 if isinstance(engine.supported_languages, dict)
                                 else engine.supported_languages,
                                 'safesearch': engine.safesearch,
                                 'time_range_support': engine.time_range_support,
                                 'timeout': engine.timeout}
                                for name, engine in engines.items() if request.preferences.validate_token(engine)],
                    'plugins': [{'name': plugin.name,
                                 'enabled': plugin.default_on}
                                for plugin in plugins],
                    'instance_name': settings['general']['instance_name'],
                    'locales': settings['locales'],
                    'default_locale': settings['ui']['default_locale'],
                    'autocomplete': settings['search']['autocomplete'],
                    'safe_search': settings['search']['safe_search'],
                    'default_theme': settings['ui']['default_theme'],
                    'version': VERSION_STRING,
                    'doi_resolvers': [r for r in settings['doi_resolvers']],
                    'default_doi_resolver': settings['default_doi_resolver'],
                    })
コード例 #4
0
def config():
    return jsonify({'categories': categories.keys(),
                    'engines': [{'name': engine_name,
                                 'categories': engine.categories,
                                 'shortcut': engine.shortcut,
                                 'enabled': not engine.disabled,
                                 'paging': engine.paging,
                                 'language_support': engine.language_support,
                                 'supported_languages':
                                 engine.supported_languages.keys()
                                 if isinstance(engine.supported_languages, dict)
                                 else engine.supported_languages,
                                 'safesearch': engine.safesearch,
                                 'time_range_support': engine.time_range_support,
                                 'timeout': engine.timeout}
                                for engine_name, engine in engines.items()],
                    'plugins': [{'name': plugin.name,
                                 'enabled': plugin.default_on}
                                for plugin in plugins],
                    'instance_name': settings['general']['instance_name'],
                    'locales': settings['locales'],
                    'default_locale': settings['ui']['default_locale'],
                    'autocomplete': settings['search']['autocomplete'],
                    'safe_search': settings['search']['safe_search'],
                    'default_theme': settings['ui']['default_theme'],
                    'version': VERSION_STRING})
コード例 #5
0
def stats():
    """Render engine statistics page."""
    sort_order = request.args.get('sort', default='name', type=str)
    selected_engine_name = request.args.get('engine', default=None, type=str)

    filtered_engines = dict(
        filter(lambda kv: (kv[0], request.preferences.validate_token(kv[1])),
               engines.items()))
    if selected_engine_name:
        if selected_engine_name not in filtered_engines:
            selected_engine_name = None
        else:
            filtered_engines = [selected_engine_name]

    checker_results = checker_get_result()
    checker_results = (checker_results['engines']
                       if checker_results['status'] == 'ok'
                       and 'engines' in checker_results else {})

    engine_stats = get_engines_stats(filtered_engines)
    engine_reliabilities = get_reliabilities(filtered_engines, checker_results)

    if sort_order not in STATS_SORT_PARAMETERS:
        sort_order = 'name'

    reverse, key_name, default_value = STATS_SORT_PARAMETERS[sort_order]

    def get_key(engine_stat):
        reliability = engine_reliabilities.get(engine_stat['name']).get(
            'reliablity', 0)
        reliability_order = 0 if reliability else 1
        if key_name == 'reliability':
            key = reliability
            reliability_order = 0
        else:
            key = engine_stat.get(key_name) or default_value
            if reverse:
                reliability_order = 1 - reliability_order
        return (reliability_order, key, engine_stat['name'])

    engine_stats['time'] = sorted(engine_stats['time'],
                                  reverse=reverse,
                                  key=get_key)
    return render(
        'stats.html',
        sort_order=sort_order,
        engine_stats=engine_stats,
        engine_reliabilities=engine_reliabilities,
        selected_engine_name=selected_engine_name,
    )
コード例 #6
0
ファイル: webapp.py プロジェクト: blyxxyz/searx
def config():
    return jsonify({'categories': categories.keys(),
                    'engines': [{'name': engine_name,
                                 'categories': engine.categories,
                                 'enabled': not engine.disabled}
                                for engine_name, engine in engines.items()],
                    'plugins': [{'name': plugin.name,
                                 'enabled': plugin.default_on}
                                for plugin in plugins],
                    'instance_name': settings['general']['instance_name'],
                    'locales': settings['locales'],
                    'default_locale': settings['ui']['default_locale'],
                    'autocomplete': settings['search']['autocomplete'],
                    'safe_search': settings['search']['safe_search'],
                    'default_theme': settings['ui']['default_theme']})
コード例 #7
0
def config():
    """Return configuration in JSON format."""
    _engines = []
    for name, engine in engines.items():
        if not request.preferences.validate_token(engine):
            continue

        supported_languages = engine.supported_languages
        if isinstance(engine.supported_languages, dict):
            supported_languages = list(engine.supported_languages.keys())

        _engines.append({
            'name': name,
            'categories': engine.categories,
            'shortcut': engine.shortcut,
            'enabled': not engine.disabled,
            'paging': engine.paging,
            'language_support': engine.language_support,
            'supported_languages': supported_languages,
            'safesearch': engine.safesearch,
            'time_range_support': engine.time_range_support,
            'timeout': engine.timeout
        })

    _plugins = []
    for _ in plugins:
        _plugins.append({'name': _.name, 'enabled': _.default_on})

    return jsonify({
        'categories': list(categories.keys()),
        'engines': _engines,
        'plugins': _plugins,
        'instance_name': settings['general']['instance_name'],
        'locales': settings['locales'],
        'default_locale': settings['ui']['default_locale'],
        'autocomplete': settings['search']['autocomplete'],
        'safe_search': settings['search']['safe_search'],
        'default_theme': settings['ui']['default_theme'],
        'version': VERSION_STRING,
        'brand': {
            'CONTACT_URL': brand.CONTACT_URL,
            'GIT_URL': brand.GIT_URL,
            'GIT_BRANCH': brand.GIT_BRANCH,
            'DOCS_URL': brand.DOCS_URL
        },
        'doi_resolvers': [r for r in settings['doi_resolvers']],
        'default_doi_resolver': settings['default_doi_resolver'],
    })
コード例 #8
0
def config():
    """Return configuration in JSON format."""
    _engines = []
    for name, engine in engines.items():
        if not request.preferences.validate_token(engine):
            continue

        supported_languages = engine.supported_languages
        if isinstance(engine.supported_languages, dict):
            supported_languages = list(engine.supported_languages.keys())

        _engines.append({
            "name": name,
            "categories": engine.categories,
            "shortcut": engine.shortcut,
            "enabled": not engine.disabled,
            "paging": engine.paging,
            "language_support": engine.language_support,
            "supported_languages": supported_languages,
            "safesearch": engine.safesearch,
            "time_range_support": engine.time_range_support,
            "timeout": engine.timeout,
        })

    _plugins = []
    for _ in plugins:
        _plugins.append({"name": _.name, "enabled": _.default_on})

    return jsonify({
        "categories": list(categories.keys()),
        "engines": _engines,
        "plugins": _plugins,
        "instance_name": settings["general"]["instance_name"],
        "locales": settings["locales"],
        "default_locale": settings["ui"]["default_locale"],
        "autocomplete": settings["search"]["autocomplete"],
        "safe_search": settings["search"]["safe_search"],
        "default_theme": settings["ui"]["default_theme"],
        "version": VERSION_STRING,
        "brand": {
            "GIT_URL": brand.GIT_URL,
            "DOCS_URL": brand.DOCS_URL
        },
        "doi_resolvers": [r for r in settings["doi_resolvers"]],
        "default_doi_resolver": settings["default_doi_resolver"],
    })
コード例 #9
0
ファイル: webapp.py プロジェクト: kvch/searx
def config():
    return jsonify(
        {
            "categories": categories.keys(),
            "engines": [
                {
                    "name": engine_name,
                    "categories": engine.categories,
                    "shortcut": engine.shortcut,
                    "enabled": not engine.disabled,
                }
                for engine_name, engine in engines.items()
            ],
            "plugins": [{"name": plugin.name, "enabled": plugin.default_on} for plugin in plugins],
            "instance_name": settings["general"]["instance_name"],
            "locales": settings["locales"],
            "default_locale": settings["ui"]["default_locale"],
            "autocomplete": settings["search"]["autocomplete"],
            "safe_search": settings["search"]["safe_search"],
            "default_theme": settings["ui"]["default_theme"],
            "version": VERSION_STRING,
        }
    )
コード例 #10
0
def preferences():
    """Render preferences page && save user preferences"""

    # pylint: disable=too-many-locals, too-many-return-statements, too-many-branches
    # pylint: disable=too-many-statements

    # save preferences
    if request.method == 'POST':
        resp = make_response(redirect(url_for('index', _external=True)))
        try:
            request.preferences.parse_form(request.form)
        except ValidationException:
            request.errors.append(
                gettext('Invalid settings, please edit your preferences'))
            return resp
        return request.preferences.save(resp)

    # render preferences
    image_proxy = request.preferences.get_value('image_proxy')  # pylint: disable=redefined-outer-name
    disabled_engines = request.preferences.engines.get_disabled()
    allowed_plugins = request.preferences.plugins.get_enabled()

    # stats for preferences page
    filtered_engines = dict(
        filter(lambda kv: (kv[0], request.preferences.validate_token(kv[1])),
               engines.items()))

    engines_by_category = {}
    for c in categories:
        engines_by_category[c] = [
            e for e in categories[c] if e.name in filtered_engines
        ]
        # sort the engines alphabetically since the order in settings.yml is meaningless.
        list.sort(engines_by_category[c], key=lambda e: e.name)

    # get first element [0], the engine time,
    # and then the second element [1] : the time (the first one is the label)
    stats = {}  # pylint: disable=redefined-outer-name
    max_rate95 = 0
    for _, e in filtered_engines.items():
        h = histogram('engine', e.name, 'time', 'total')
        median = round(h.percentage(50), 1) if h.count > 0 else None
        rate80 = round(h.percentage(80), 1) if h.count > 0 else None
        rate95 = round(h.percentage(95), 1) if h.count > 0 else None

        max_rate95 = max(max_rate95, rate95 or 0)

        result_count_sum = histogram('engine', e.name, 'result', 'count').sum
        successful_count = counter('engine', e.name, 'search', 'count',
                                   'successful')
        result_count = int(result_count_sum /
                           float(successful_count)) if successful_count else 0

        stats[e.name] = {
            'time':
            median,
            'rate80':
            rate80,
            'rate95':
            rate95,
            'warn_timeout':
            e.timeout > settings['outgoing']['request_timeout'],
            'supports_selected_language':
            _is_selected_language_supported(e, request.preferences),
            'result_count':
            result_count,
        }
    # end of stats

    # reliabilities
    reliabilities = {}
    engine_errors = get_engine_errors(filtered_engines)
    checker_results = checker_get_result()
    checker_results = checker_results['engines'] \
        if checker_results['status'] == 'ok' and 'engines' in checker_results else {}
    for _, e in filtered_engines.items():
        checker_result = checker_results.get(e.name, {})
        checker_success = checker_result.get('success', True)
        errors = engine_errors.get(e.name) or []
        if counter('engine', e.name, 'search', 'count', 'sent') == 0:
            # no request
            reliablity = None
        elif checker_success and not errors:
            reliablity = 100
        elif 'simple' in checker_result.get('errors', {}):
            # the basic (simple) test doesn't work: the engine is broken accoding to the checker
            # even if there is no exception
            reliablity = 0
        else:
            reliablity = 100 - sum([
                error['percentage']
                for error in errors if not error.get('secondary')
            ])

        reliabilities[e.name] = {
            'reliablity': reliablity,
            'errors': [],
            'checker': checker_results.get(e.name, {}).get('errors',
                                                           {}).keys(),
        }
        # keep the order of the list checker_results[e.name]['errors'] and deduplicate.
        # the first element has the highest percentage rate.
        reliabilities_errors = []
        for error in errors:
            error_user_text = None
            if error.get('secondary') or 'exception_classname' not in error:
                continue
            error_user_text = exception_classname_to_text.get(
                error.get('exception_classname'))
            if not error:
                error_user_text = exception_classname_to_text[None]
            if error_user_text not in reliabilities_errors:
                reliabilities_errors.append(error_user_text)
        reliabilities[e.name]['errors'] = reliabilities_errors

    # supports
    supports = {}
    for _, e in filtered_engines.items():
        supports_selected_language = _is_selected_language_supported(
            e, request.preferences)
        safesearch = e.safesearch
        time_range_support = e.time_range_support
        for checker_test_name in checker_results.get(e.name,
                                                     {}).get('errors', {}):
            if supports_selected_language and checker_test_name.startswith(
                    'lang_'):
                supports_selected_language = '?'
            elif safesearch and checker_test_name == 'safesearch':
                safesearch = '?'
            elif time_range_support and checker_test_name == 'time_range':
                time_range_support = '?'
        supports[e.name] = {
            'supports_selected_language': supports_selected_language,
            'safesearch': safesearch,
            'time_range_support': time_range_support,
        }

    return render(
        'preferences.html',
        selected_categories=get_selected_categories(request.preferences,
                                                    request.form),
        locales=settings['locales'],
        current_locale=request.preferences.get_value("locale"),
        image_proxy=image_proxy,
        engines_by_category=engines_by_category,
        stats=stats,
        max_rate95=max_rate95,
        reliabilities=reliabilities,
        supports=supports,
        answerers=[{
            'info': a.self_info(),
            'keywords': a.keywords
        } for a in answerers],
        disabled_engines=disabled_engines,
        autocomplete_backends=autocomplete_backends,
        shortcuts={y: x
                   for x, y in engine_shortcuts.items()},
        themes=themes,
        plugins=plugins,
        doi_resolvers=settings['doi_resolvers'],
        current_doi_resolver=get_doi_resolver(
            request.args, request.preferences.get_value('doi_resolver')),
        allowed_plugins=allowed_plugins,
        theme=get_current_theme_name(),
        preferences_url_params=request.preferences.get_as_url_params(),
        locked_preferences=settings['preferences']['lock'],
        preferences=True)
コード例 #11
0
def stats_errors():
    filtered_engines = dict(
        filter(lambda kv: (kv[0], request.preferences.validate_token(kv[1])),
               engines.items()))
    result = get_engine_errors(filtered_engines)
    return jsonify(result)