mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-06 06:52:20 +02:00
separate search freshness from news category selection
This commit is contained in:
@@ -150,7 +150,7 @@ def _safesearch_for(provider: str) -> Optional[str]:
|
|||||||
# ── SearXNG ──
|
# ── SearXNG ──
|
||||||
|
|
||||||
_NEWS_HINTS = (
|
_NEWS_HINTS = (
|
||||||
"news", "nyheter", "headlines", "breaking", "latest", "today", "idag",
|
"news", "nyheter", "headlines", "breaking", "idag",
|
||||||
"current events", "what's happening", "what is happening",
|
"current events", "what's happening", "what is happening",
|
||||||
)
|
)
|
||||||
_NEWS_EVENT_HINT_RE = re.compile(
|
_NEWS_EVENT_HINT_RE = re.compile(
|
||||||
@@ -213,8 +213,7 @@ def searxng_search_api(query: str, count: Optional[int] = None, categories: str
|
|||||||
is_news = (
|
is_news = (
|
||||||
not is_software_release_query
|
not is_software_release_query
|
||||||
and (
|
and (
|
||||||
time_filter is not None
|
any(h in q_lc for h in _NEWS_HINTS)
|
||||||
or any(h in q_lc for h in _NEWS_HINTS)
|
|
||||||
or bool(_NEWS_EVENT_HINT_RE.search(query))
|
or bool(_NEWS_EVENT_HINT_RE.search(query))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -226,6 +225,10 @@ def searxng_search_api(query: str, count: Optional[int] = None, categories: str
|
|||||||
params["time_range"] = "week" if time_filter in ("day", "week") else time_filter
|
params["time_range"] = "week" if time_filter in ("day", "week") else time_filter
|
||||||
else:
|
else:
|
||||||
params["categories"] = categories
|
params["categories"] = categories
|
||||||
|
# Freshness and source category are independent: current manuals,
|
||||||
|
# comparisons and documentation still belong in general search.
|
||||||
|
if not is_software_release_query and time_filter in ("day", "week", "month", "year"):
|
||||||
|
params["time_range"] = time_filter
|
||||||
# Route general queries to engines that aren't blocked (default general
|
# Route general queries to engines that aren't blocked (default general
|
||||||
# set returns 0 on this instance — see _GENERAL_ENGINES).
|
# set returns 0 on this instance — see _GENERAL_ENGINES).
|
||||||
if categories == "general" and _GENERAL_ENGINES:
|
if categories == "general" and _GENERAL_ENGINES:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ behavior at the single implementation point.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import pytest
|
||||||
|
|
||||||
from services.search import core
|
from services.search import core
|
||||||
from services.search import providers
|
from services.search import providers
|
||||||
@@ -74,7 +75,12 @@ def test_service_searxng_json_sends_safesearch(monkeypatch):
|
|||||||
assert seen["params"]["safesearch"] == "1"
|
assert seen["params"]["safesearch"] == "1"
|
||||||
|
|
||||||
|
|
||||||
def test_service_searxng_latest_release_uses_general_search(monkeypatch):
|
@pytest.mark.parametrize('query,expected_time', [
|
||||||
|
('latest ollama release version github', None),
|
||||||
|
('current Firefox Chrome privacy features comparison', 'day'),
|
||||||
|
('Sony headphone manual', 'day'),
|
||||||
|
])
|
||||||
|
def test_service_searxng_latest_release_uses_general_search(monkeypatch, query, expected_time):
|
||||||
seen = {}
|
seen = {}
|
||||||
|
|
||||||
class _Response:
|
class _Response:
|
||||||
@@ -101,7 +107,7 @@ def test_service_searxng_latest_release_uses_general_search(monkeypatch):
|
|||||||
monkeypatch.setattr(providers.httpx, "get", fake_get)
|
monkeypatch.setattr(providers.httpx, "get", fake_get)
|
||||||
|
|
||||||
results = providers.searxng_search_api(
|
results = providers.searxng_search_api(
|
||||||
"latest ollama release version github",
|
query,
|
||||||
count=1,
|
count=1,
|
||||||
time_filter="day",
|
time_filter="day",
|
||||||
)
|
)
|
||||||
@@ -109,7 +115,7 @@ def test_service_searxng_latest_release_uses_general_search(monkeypatch):
|
|||||||
assert results
|
assert results
|
||||||
assert seen["params"]["categories"] == "general"
|
assert seen["params"]["categories"] == "general"
|
||||||
assert seen["params"]["engines"] == providers._GENERAL_ENGINES
|
assert seen["params"]["engines"] == providers._GENERAL_ENGINES
|
||||||
assert "time_range" not in seen["params"]
|
assert seen['params'].get('time_range') == expected_time
|
||||||
|
|
||||||
|
|
||||||
def test_service_searxng_specific_current_event_uses_news_search(monkeypatch):
|
def test_service_searxng_specific_current_event_uses_news_search(monkeypatch):
|
||||||
|
|||||||
Reference in New Issue
Block a user