mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-11-04 20:22:21 +01:00
Preserve publication windows through news-provider fallbacks
This commit is contained in:
@@ -263,17 +263,11 @@ def searxng_search_api(query: str, count: Optional[int] = None, categories: str
|
|||||||
|
|
||||||
active_params = params
|
active_params = params
|
||||||
parsed, data = _run(active_params)
|
parsed, data = _run(active_params)
|
||||||
if not parsed and is_news and categories == "general":
|
if not parsed and active_params.get("categories") == "news":
|
||||||
# Some self-hosted SearXNG configs have no working news engines.
|
# Some self-hosted SearXNG configs have no working news engines.
|
||||||
# Fall back to the known-good general engines before reporting an
|
# Fall back to the known-good general engines before reporting an
|
||||||
# empty search, otherwise common queries like "Canada news" fail.
|
# empty search, otherwise common queries like "Canada news" fail.
|
||||||
fallback = {
|
fallback = {**active_params, "categories": "general"}
|
||||||
"q": query,
|
|
||||||
"format": "json",
|
|
||||||
"language": "en",
|
|
||||||
"categories": "general",
|
|
||||||
"safesearch": _safesearch_for("searxng"),
|
|
||||||
}
|
|
||||||
if _GENERAL_ENGINES:
|
if _GENERAL_ENGINES:
|
||||||
fallback["engines"] = _GENERAL_ENGINES
|
fallback["engines"] = _GENERAL_ENGINES
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -60,6 +60,25 @@ def test_provider_does_not_silently_widen_news_window(monkeypatch):
|
|||||||
assert seen['time_range'] == 'day'
|
assert seen['time_range'] == 'day'
|
||||||
|
|
||||||
|
|
||||||
|
def test_provider_keeps_news_date_window_across_empty_fallbacks(monkeypatch):
|
||||||
|
from services.search import providers
|
||||||
|
calls = []
|
||||||
|
class Response:
|
||||||
|
def raise_for_status(self): pass
|
||||||
|
def json(self): return {'results': []}
|
||||||
|
def get(url, **kwargs):
|
||||||
|
calls.append(dict(kwargs['params']))
|
||||||
|
return Response()
|
||||||
|
monkeypatch.setattr(providers, '_get_search_instance', lambda: 'http://searx.test')
|
||||||
|
monkeypatch.setattr(providers, '_get_search_settings', lambda: {})
|
||||||
|
monkeypatch.setattr(providers.httpx, 'get', get)
|
||||||
|
providers.searxng_search_api('AI news today', time_filter='day')
|
||||||
|
assert len(calls) >= 2
|
||||||
|
assert calls[0]['categories'] == 'news'
|
||||||
|
assert calls[1]['categories'] == 'general'
|
||||||
|
assert all(call['time_range'] == 'day' for call in calls)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('arguments,expected', [
|
@pytest.mark.parametrize('arguments,expected', [
|
||||||
({'query': 'latest browser documentation'}, None),
|
({'query': 'latest browser documentation'}, None),
|
||||||
({'query': 'browser documentation', 'time_filter': 'month'}, 'month'),
|
({'query': 'browser documentation', 'time_filter': 'month'}, 'month'),
|
||||||
|
|||||||
Reference in New Issue
Block a user