Merge remote-tracking branch 'searxng/master'

This commit is contained in:
Valentin Riess 2024-02-10 15:52:51 +01:00
commit f9671ea712
10 changed files with 67 additions and 84 deletions

View file

@ -170,4 +170,5 @@ features or generally made searx better:
- @blob42 `<https://blob42.xyz>`_
- Paolo Basso `<https://github.com/paolobasso99>`
- Bernie Huang `<https://github.com/BernieHuang2008>`
- Valentin Rieß `<https://github.com/v411e>`
- Austin Olacsi `<https://github.com/Austin-Olacsi>`
- Valentin Rieß `<https://github.com/v411e>`

View file

@ -18,6 +18,6 @@ sphinx-notfound-page==1.0.0
myst-parser==2.0.0
linuxdoc==20231020
aiounittest==1.4.2
yamllint==1.33.0
yamllint==1.34.0
wlc==1.13
coloredlogs==15.0.1

View file

@ -1,7 +1,7 @@
certifi==2023.11.17
certifi==2024.2.2
babel==2.14.0
flask-babel==4.0.0
flask==3.0.1
flask==3.0.2
jinja2==3.1.3
lxml==5.1.0
pygments==2.17.2

View file

@ -1,73 +0,0 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
# pyright: basic
"""Module for backward compatibility.
"""
# pylint: disable=C,R
__all__ = ('cached_property',)
try:
from functools import cached_property # type: ignore
except ImportError:
# cache_property has been added in py3.8 [1]
#
# To support cache_property in py3.7 the implementation from 3.8 has been
# copied here. This code can be cleanup with EOL of py3.7.
#
# [1] https://docs.python.org/3/library/functools.html#functools.cached_property
from threading import RLock
_NOT_FOUND = object()
class cached_property:
def __init__(self, func):
self.func = func
self.attrname = None
self.__doc__ = func.__doc__
self.lock = RLock()
def __set_name__(self, owner, name):
if self.attrname is None:
self.attrname = name
elif name != self.attrname:
raise TypeError(
"Cannot assign the same cached_property to two different names "
f"({self.attrname!r} and {name!r})."
)
def __get__(self, instance, owner=None):
if instance is None:
return self
if self.attrname is None:
raise TypeError("Cannot use cached_property instance without calling __set_name__ on it.")
try:
cache = instance.__dict__
except AttributeError: # not all objects have __dict__ (e.g. class defines slots)
msg = (
f"No '__dict__' attribute on {type(instance).__name__!r} "
f"instance to cache {self.attrname!r} property."
)
raise TypeError(msg) from None
val = cache.get(self.attrname, _NOT_FOUND)
if val is _NOT_FOUND:
with self.lock:
# check if another thread filled cache while we awaited lock
val = cache.get(self.attrname, _NOT_FOUND)
if val is _NOT_FOUND:
val = self.func(instance)
try:
cache[self.attrname] = val
except TypeError:
msg = (
f"The '__dict__' attribute on {type(instance).__name__!r} instance "
f"does not support item assignment for caching {self.attrname!r} property."
)
raise TypeError(msg) from None
return val

View file

@ -30,6 +30,13 @@ Configured ``brave`` engines:
...
brave_category: news
- name: brave.goggles
brave_category: goggles
time_range_support: true
paging: true
...
brave_category: goggles
.. _brave regions:
@ -58,6 +65,23 @@ region are mapped to regions in SearXNG (see :py:obj:`babel
low quality.
.. _brave googles:
Brave Goggles
=============
.. _list of Goggles: https://search.brave.com/goggles/discover
.. _Goggles Whitepaper: https://brave.com/static-assets/files/goggles.pdf
.. _Goggles Quickstart: https://github.com/brave/goggles-quickstart
Goggles allow you to choose, alter, or extend the ranking of Brave Search
results (`Goggles Whitepaper`_). Goggles are openly developed by the community
of Brave Search users.
Select from the `list of Goggles`_ people have published, or create your own
(`Goggles Quickstart`_).
.. _brave languages:
Brave languages
@ -95,7 +119,7 @@ Implementations
"""
from typing import TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from urllib.parse import (
urlencode,
@ -135,12 +159,14 @@ about = {
base_url = "https://search.brave.com/"
categories = []
brave_category = 'search'
"""Brave supports common web-search, video search, image and video search.
Goggles = Any
"""Brave supports common web-search, videos, images, news, and goggles search.
- ``search``: Common WEB search
- ``videos``: search for videos
- ``images``: search for images
- ``news``: search for news
- ``goggles``: Common WEB search with custom rules
"""
brave_spellcheck = False
@ -153,7 +179,7 @@ in SearXNG, the spellchecking is disabled by default.
send_accept_language_header = True
paging = False
"""Brave only supports paging in :py:obj:`brave_category` ``search`` (UI
category All)."""
category All) and in the goggles category."""
max_page = 10
"""Tested 9 pages maximum (``&offset=8``), to be save max is set to 10. Trying
to do more won't return any result and you will most likely be flagged as a bot.
@ -164,7 +190,7 @@ safesearch_map = {2: 'strict', 1: 'moderate', 0: 'off'} # cookie: safesearch=of
time_range_support = False
"""Brave only supports time-range in :py:obj:`brave_category` ``search`` (UI
category All)."""
category All) and in the goggles category."""
time_range_map = {
'day': 'pd',
@ -185,12 +211,15 @@ def request(query, params):
if brave_spellcheck:
args['spellcheck'] = '1'
if brave_category == 'search':
if brave_category in ('search', 'goggles'):
if params.get('pageno', 1) - 1:
args['offset'] = params.get('pageno', 1) - 1
if time_range_map.get(params['time_range']):
args['tf'] = time_range_map.get(params['time_range'])
if brave_category == 'goggles':
args['goggles_id'] = Goggles
params["url"] = f"{base_url}{brave_category}?{urlencode(args)}"
# set properties in the cookies
@ -221,7 +250,7 @@ def _extract_published_date(published_date_raw):
def response(resp):
if brave_category == 'search':
if brave_category in ('search', 'goggles'):
return _parse_search(resp)
datastr = ""

View file

@ -27,12 +27,12 @@ import logging
import typing
import urllib.parse
from functools import cached_property
import jinja2
from flask.helpers import url_for
from markdown_it import MarkdownIt
from .. import get_setting
from ..compat import cached_property
from ..version import GIT_URL
from ..locales import LOCALE_NAMES

View file

@ -11,6 +11,7 @@ __all__ = [
'CATEGORY_NAMES',
'CATEGORY_GROUPS',
'STYLE_NAMES',
'BRAND_CUSTOM_LINKS',
]
CONSTANT_NAMES = {
@ -51,3 +52,8 @@ STYLE_NAMES = {
'LIGHT': 'light',
'DARK': 'dark',
}
BRAND_CUSTOM_LINKS = {
'UPTIME': 'Uptime',
'ABOUT': 'About',
}

View file

@ -19,6 +19,12 @@ brand:
public_instances: https://searx.space
wiki_url: https://github.com/searxng/searxng/wiki
issue_url: https://github.com/searxng/searxng/issues
# custom:
# maintainer: "Jon Doe"
# # Custom entries in the footer: [title]: [link]
# links:
# Uptime: https://uptime.searxng.org/history/darmarit-org
# About: "https://searxng.org"
search:
# Filter results. 0: None, 1: Moderate, 2: Strict
@ -2167,6 +2173,16 @@ engines:
categories: news
brave_category: news
# - name: brave.goggles
# engine: brave
# network: brave
# shortcut: brgog
# time_range_support: true
# paging: true
# categories: [general, web]
# brave_category: goggles
# Goggles: # required! This should be a URL ending in .goggle
- name: lib.rs
shortcut: lrs
engine: xpath

View file

@ -151,6 +151,7 @@ SCHEMA = {
'docs_url': SettingsValue(str, 'https://docs.searxng.org'),
'public_instances': SettingsValue((False, str), 'https://searx.space'),
'wiki_url': SettingsValue(str, 'https://github.com/searxng/searxng/wiki'),
'custom': SettingsValue(dict, {'links': {}}),
},
'search': {
'safe_search': SettingsValue((0, 1, 2), 0),

View file

@ -77,6 +77,9 @@
{% if get_setting('general.contact_url') %}
| <a href="{{ get_setting('general.contact_url') }}">{{ _('Contact instance maintainer') }}</a>
{% endif %}
{% for title, link in get_setting('brand.custom.links').items() %}
| <a href="{{ link }}">{{ _(title) }}</a>
{% endfor %}
</p>
</footer>
<!--[if gte IE 9]>-->