mirror of
https://github.com/searxng/searxng.git
synced 2026-07-17 21:41:24 +00:00
Compare commits
12 Commits
58e02a01ae
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81c9c23862 | ||
|
|
6913fba208 | ||
|
|
2daa4d4815 | ||
|
|
de8f73f434 | ||
|
|
9f9c00819e | ||
|
|
b72a87676f | ||
|
|
f2432e33d6 | ||
|
|
7b2199ecdf | ||
|
|
4a9c19d7bf | ||
|
|
5cb4cb2bc5 | ||
|
|
5a448596ab | ||
|
|
9c49b7e0d7 |
2
.github/workflows/integration.yml
vendored
2
.github/workflows/integration.yml
vendored
@@ -67,7 +67,7 @@ jobs:
|
|||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||||
with:
|
with:
|
||||||
node-version: "26"
|
node-version: "26"
|
||||||
check-latest: "true"
|
check-latest: "true"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ cov-core==1.15.0
|
|||||||
black==25.9.0
|
black==25.9.0
|
||||||
pylint==4.0.6
|
pylint==4.0.6
|
||||||
splinter==0.21.0
|
splinter==0.21.0
|
||||||
selenium==4.45.0
|
selenium==4.46.0
|
||||||
Sphinx==8.2.3;python_version <= "3.11"
|
Sphinx==8.2.3;python_version <= "3.11"
|
||||||
Sphinx==9.1.0; python_version > "3.11"
|
Sphinx==9.1.0; python_version > "3.11"
|
||||||
sphinx-issues==6.0.0
|
sphinx-issues==6.0.0
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ sniffio==1.3.1
|
|||||||
valkey==6.1.1
|
valkey==6.1.1
|
||||||
markdown-it-py==4.2.0
|
markdown-it-py==4.2.0
|
||||||
msgspec==0.21.1
|
msgspec==0.21.1
|
||||||
typer==0.26.8
|
typer==0.27.0
|
||||||
isodate==0.7.2
|
isodate==0.7.2
|
||||||
whitenoise==6.12.0
|
whitenoise==6.12.0
|
||||||
typing-extensions==4.16.0
|
typing-extensions==4.16.0
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ExpireCacheCfg(msgspec.Struct): # pylint: disable=too-few-public-methods
|
|||||||
MAXHOLD_TIME: int = 60 * 60 * 24 * 7 # 7 days
|
MAXHOLD_TIME: int = 60 * 60 * 24 * 7 # 7 days
|
||||||
"""Hold time (default in sec.), after which a value is removed from the cache."""
|
"""Hold time (default in sec.), after which a value is removed from the cache."""
|
||||||
|
|
||||||
MAINTENANCE_PERIOD: int = 60 * 60 # 2h
|
MAINTENANCE_PERIOD: int = 60 * 60 # 1h
|
||||||
"""Maintenance period in seconds / when :py:obj:`MAINTENANCE_MODE` is set to
|
"""Maintenance period in seconds / when :py:obj:`MAINTENANCE_MODE` is set to
|
||||||
``auto``."""
|
``auto``."""
|
||||||
|
|
||||||
@@ -458,12 +458,22 @@ class ExpireCacheSQLite(sqlitedb.SQLiteAppl, ExpireCache):
|
|||||||
# Before values are taken from the table, a maintenance interval may
|
# Before values are taken from the table, a maintenance interval may
|
||||||
# need to be carried out.
|
# need to be carried out.
|
||||||
self.maintenance()
|
self.maintenance()
|
||||||
sql = f"SELECT value FROM {table} WHERE key = ?"
|
sql = f"SELECT value, expire FROM {table} WHERE key = ?"
|
||||||
row = self.DB.execute(sql, (key,)).fetchone()
|
row = self.DB.execute(sql, (key,)).fetchone()
|
||||||
if row is None:
|
if row is None:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
return self.deserialize(row[0])
|
# Check if value is expired. It's possible that it's expired but has not
|
||||||
|
# yet been automatically deleted by the periodic maintenance
|
||||||
|
(value, expire) = row
|
||||||
|
now = time.time()
|
||||||
|
if expire < now:
|
||||||
|
# The record is deleted during the maintenance interval. Deleting
|
||||||
|
# the record at this point offers no advantage, as a SELECT
|
||||||
|
# statement must be executed for every cache.get request anyways.
|
||||||
|
return default
|
||||||
|
|
||||||
|
return self.deserialize(value)
|
||||||
|
|
||||||
def pairs(self, ctx: str) -> Iterator[tuple[str, typing.Any]]:
|
def pairs(self, ctx: str) -> Iterator[tuple[str, typing.Any]]:
|
||||||
"""Iterate over key/value pairs from table given by argument ``ctx``.
|
"""Iterate over key/value pairs from table given by argument ``ctx``.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ ENGINES_CACHE: ExpireCacheSQLite = ExpireCacheSQLite.build_cache(
|
|||||||
ExpireCacheCfg(
|
ExpireCacheCfg(
|
||||||
name="ENGINES_CACHE",
|
name="ENGINES_CACHE",
|
||||||
MAXHOLD_TIME=60 * 60 * 24 * 7, # 7 days
|
MAXHOLD_TIME=60 * 60 * 24 * 7, # 7 days
|
||||||
MAINTENANCE_PERIOD=60 * 60, # 2h
|
MAINTENANCE_PERIOD=60 * 60, # 1h
|
||||||
MAX_VALUE_LEN=1024 * 1024 * 1024, # 1MB
|
MAX_VALUE_LEN=1024 * 1024 * 1024, # 1MB
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ def response(resp):
|
|||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
'url': _clean_url(f"{about['website']}/images/{result['objectID']}"),
|
'url': _clean_url(f"{pdia_base_url}/images/{result['objectID']}"),
|
||||||
'img_src': _clean_url(base_image_url),
|
'img_src': _clean_url(base_image_url),
|
||||||
'thumbnail_src': _clean_url(base_image_url + THUMBNAIL_SUFFIX),
|
'thumbnail_src': _clean_url(base_image_url + THUMBNAIL_SUFFIX),
|
||||||
'title': f"{result['title'].strip()} by {result['artist']} {result.get('displayYear', '')}",
|
'title': f"{result['title'].strip()} by {result['artist']} {result.get('displayYear', '')}",
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ from urllib.parse import urlencode
|
|||||||
import babel
|
import babel
|
||||||
from flask_babel import gettext # pyright: ignore[reportUnknownVariableType]
|
from flask_babel import gettext # pyright: ignore[reportUnknownVariableType]
|
||||||
|
|
||||||
|
from searx.enginelib import EngineCache
|
||||||
from searx.enginelib.traits import EngineTraits
|
from searx.enginelib.traits import EngineTraits
|
||||||
from searx.exceptions import (
|
from searx.exceptions import (
|
||||||
SearxEngineAccessDeniedException,
|
SearxEngineAccessDeniedException,
|
||||||
@@ -105,9 +106,19 @@ qwant_news_locales = [
|
|||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
base_url = "https://www.qwant.com"
|
||||||
api_url = "https://api.qwant.com/v3/search/"
|
api_url = "https://api.qwant.com/v3/search/"
|
||||||
"""URL of Qwant's API (JSON)"""
|
"""URL of Qwant's API (JSON)"""
|
||||||
|
|
||||||
|
CACHE: EngineCache
|
||||||
|
"""Cache for storing the ``datadome`` cookie."""
|
||||||
|
|
||||||
|
|
||||||
|
def setup(engine_settings: dict[str, t.Any]) -> bool:
|
||||||
|
global CACHE # pylint: disable=global-statement
|
||||||
|
CACHE = EngineCache(engine_settings["name"])
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def request(query: str, params: "OnlineParams") -> None:
|
def request(query: str, params: "OnlineParams") -> None:
|
||||||
"""Qwant search request"""
|
"""Qwant search request"""
|
||||||
@@ -129,24 +140,29 @@ def request(query: str, params: "OnlineParams") -> None:
|
|||||||
"tgp": test_group_value,
|
"tgp": test_group_value,
|
||||||
"device": "desktop",
|
"device": "desktop",
|
||||||
"safesearch": params["safesearch"],
|
"safesearch": params["safesearch"],
|
||||||
"display": True,
|
# True would be encoded to "True", instead of "true", which makes the request
|
||||||
"llm": True,
|
# easier to detect and block
|
||||||
|
"displayed": "true",
|
||||||
|
"llm": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
# shuffle query parameters to be harder to fingerprint
|
|
||||||
args = list(args.items())
|
|
||||||
random.shuffle(args)
|
|
||||||
args = dict(args)
|
|
||||||
|
|
||||||
params["raise_for_httperror"] = False
|
params["raise_for_httperror"] = False
|
||||||
|
|
||||||
params["url"] = f"{api_url}{qwant_categ}?{urlencode(args)}"
|
params["url"] = f"{api_url}{qwant_categ}?{urlencode(args)}"
|
||||||
|
|
||||||
|
params["cookies"]["datadome"] = CACHE.get("datadome")
|
||||||
|
params["headers"].update({"Accept": "application/json", "Referer": f"{base_url}/", "Origin": base_url})
|
||||||
|
|
||||||
|
|
||||||
def response(resp: "SXNG_Response") -> EngineResults:
|
def response(resp: "SXNG_Response") -> EngineResults:
|
||||||
"""Parse results from Qwant's API"""
|
"""Parse results from Qwant's API"""
|
||||||
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
||||||
|
|
||||||
|
# cache datadome cookie - changes on each request
|
||||||
|
datadome = resp.cookies.get("datadome")
|
||||||
|
if datadome:
|
||||||
|
CACHE.set("datadome", datadome)
|
||||||
|
|
||||||
res = EngineResults()
|
res = EngineResults()
|
||||||
|
|
||||||
# Try to load JSON result
|
# Try to load JSON result
|
||||||
@@ -163,8 +179,8 @@ def response(resp: "SXNG_Response") -> EngineResults:
|
|||||||
error_code = data.get("error_code")
|
error_code = data.get("error_code")
|
||||||
if error_code == 24:
|
if error_code == 24:
|
||||||
raise SearxEngineTooManyRequestsException()
|
raise SearxEngineTooManyRequestsException()
|
||||||
if search_results.get("data", {}).get("error_data", {}).get("captchaUrl") is not None:
|
if search_results.get("url") is not None:
|
||||||
raise SearxEngineCaptchaException()
|
raise SearxEngineCaptchaException(suspended_time=0)
|
||||||
if resp.status_code == 403:
|
if resp.status_code == 403:
|
||||||
raise SearxEngineAccessDeniedException()
|
raise SearxEngineAccessDeniedException()
|
||||||
msg = ",".join(data.get("message", ["unknown"]))
|
msg = ",".join(data.get("message", ["unknown"]))
|
||||||
@@ -302,7 +318,7 @@ def fetch_traits(engine_traits: EngineTraits):
|
|||||||
from searx.utils import extr
|
from searx.utils import extr
|
||||||
|
|
||||||
resp = get(
|
resp = get(
|
||||||
about["website"], # pyright: ignore[reportArgumentType]
|
base_url, # pyright: ignore[reportArgumentType]
|
||||||
timeout=5,
|
timeout=5,
|
||||||
)
|
)
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ def _obtain_session_code() -> str:
|
|||||||
if not code:
|
if not code:
|
||||||
raise SearxEngineAPIException("failed to obtain session code")
|
raise SearxEngineAPIException("failed to obtain session code")
|
||||||
|
|
||||||
CACHE.set("session", code, expire=60 * 24 * 60) # cookie is valid for two months
|
CACHE.set("session", code, expire=60 * 24 * 60 * 60) # cookie is valid for two months
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ def _normalize_url_fields(result: "Result | LegacyResult"):
|
|||||||
result.parsed_url = urllib.parse.urlparse(result.url)
|
result.parsed_url = urllib.parse.urlparse(result.url)
|
||||||
|
|
||||||
if result.parsed_url:
|
if result.parsed_url:
|
||||||
|
# properly format special characters (e.g. "ä", "ö") in IDN domains
|
||||||
|
# e.g. "xn--strung-xxa.de" becomes "störung.de"
|
||||||
|
if result.parsed_url.netloc.startswith("xn--"):
|
||||||
|
netloc = result.parsed_url.netloc.encode().decode("idna")
|
||||||
|
result.parsed_url = result.parsed_url._replace(netloc=netloc)
|
||||||
|
|
||||||
result.parsed_url = result.parsed_url._replace(
|
result.parsed_url = result.parsed_url._replace(
|
||||||
# if the result has no scheme, use http as default
|
# if the result has no scheme, use http as default
|
||||||
scheme=result.parsed_url.scheme or "http",
|
scheme=result.parsed_url.scheme or "http",
|
||||||
|
|||||||
@@ -477,6 +477,24 @@ engines:
|
|||||||
engine: arxiv
|
engine: arxiv
|
||||||
shortcut: arx
|
shortcut: arx
|
||||||
|
|
||||||
|
- name: avalw
|
||||||
|
engine: json_engine
|
||||||
|
shortcut: av
|
||||||
|
categories: general
|
||||||
|
paging: true
|
||||||
|
search_url: https://avalw.org/api/search?q={query}&page={pageno}&limit=10&tbm=all
|
||||||
|
results_query: results
|
||||||
|
url_query: url
|
||||||
|
title_query: title
|
||||||
|
content_query: snippet
|
||||||
|
thumbnail: image_url
|
||||||
|
disabled: true
|
||||||
|
inactive: true
|
||||||
|
about:
|
||||||
|
website: https://avalw.com
|
||||||
|
description: "Search engine from the Romanian news company AVALW S.R.L."
|
||||||
|
results: JSON
|
||||||
|
|
||||||
- name: ayo
|
- name: ayo
|
||||||
engine: xpath
|
engine: xpath
|
||||||
categories: general
|
categories: general
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<p class="result-filesize">{{ _label(_("Filesize"), result.filesize) }}</p>
|
<p class="result-filesize">{{ _label(_("Filesize"), result.filesize) }}</p>
|
||||||
<p class="result-source">{{ _label(_("Source"), result.source) }}</p>
|
<p class="result-source">{{ _label(_("Source"), result.source) }}</p>
|
||||||
<p class="result-engine">{{ _label(_("Engine"), result.engine) }}</p>
|
<p class="result-engines">{{ _label(_("Engines"), ", ".join(result.engines)) }}</p>
|
||||||
<p class="result-url"><span>{{ _("View source") }}:</span>{{- "" -}}
|
<p class="result-url"><span>{{ _("View source") }}:</span>{{- "" -}}
|
||||||
<a {{ _target(results_on_new_tab) }} href="{{ result.url }}">{{ result.url }}</a>
|
<a {{ _target(results_on_new_tab) }} href="{{ result.url }}">{{ result.url }}</a>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -845,7 +845,10 @@ def autocompleter():
|
|||||||
mimetype = 'application/json'
|
mimetype = 'application/json'
|
||||||
else:
|
else:
|
||||||
# the suggestion request comes from browser's URL bar
|
# the suggestion request comes from browser's URL bar
|
||||||
suggestions = json.dumps([sug_prefix, results])
|
relevances = {
|
||||||
|
'google:suggestrelevance': [600 - i for i in range(len(results))]
|
||||||
|
} # chromium only shows 3 suggestions unless we attach relevances
|
||||||
|
suggestions = json.dumps([sug_prefix, results, [], [], relevances])
|
||||||
mimetype = 'application/x-suggestions+json'
|
mimetype = 'application/x-suggestions+json'
|
||||||
|
|
||||||
suggestions = escape(suggestions, False)
|
suggestions = escape(suggestions, False)
|
||||||
|
|||||||
Reference in New Issue
Block a user