Skip to content

Self-hosted AI workspace.

Python

separate search freshness from news category selection

pewdiepie-archdaemon7fa6c93fb346
diff --git a/services/search/providers.py b/services/search/providers.py
index 32bec41ce..e94c3f731 100644
--- a/services/search/providers.py
+++ b/services/search/providers.py
@@ -150,7 +150,7 @@ def _safesearch_for(provider: str) -> Optional[str]:
# ── SearXNG ──
_NEWS_HINTS = (
- "news", "nyheter", "headlines", "breaking", "latest", "today", "idag",
+ "news", "nyheter", "headlines", "breaking", "idag",
"current events", "what's happening", "what is happening",
)
_NEWS_EVENT_HINT_RE = re.compile(
@@ -213,8 +213,7 @@ def searxng_search_api(query: str, count: Optional[int] = None, categories: str
is_news = (
not is_software_release_query
and (
- time_filter is not None
- or any(h in q_lc for h in _NEWS_HINTS)
+ any(h in q_lc for h in _NEWS_HINTS)
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
else:
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
# set returns 0 on this instance — see _GENERAL_ENGINES).
if categories == "general" and _GENERAL_ENGINES:
diff --git a/tests/test_service_search_provider_guards.py b/tests/test_service_search_provider_guards.py
index fd9576220..50a5090cc 100644
--- a/tests/test_service_search_provider_guards.py
+++ b/tests/test_service_search_provider_guards.py
@@ -5,6 +5,7 @@ behavior at the single implementation point.
"""
import sys
+import pytest
from services.search import core
from services.search import providers
@@ -74,7 +75,12 @@ def test_service_searxng_json_sends_safesearch(monkeypatch):
assert seen["params"]["safesearch"] == "1"
-def test_service_searxng_latest_release_uses_general_search(monkeypatch):
[email protected]('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 = {}
class _Response:
@@ -101,7 +107,7 @@ def test_service_searxng_latest_release_uses_general_search(monkeypatch):
monkeypatch.setattr(providers.httpx, "get", fake_get)
results = providers.searxng_search_api(
- "latest ollama release version github",
+ query,
count=1,
time_filter="day",
)
@@ -109,7 +115,7 @@ def test_service_searxng_latest_release_uses_general_search(monkeypatch):
assert results
assert seen["params"]["categories"] == "general"
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):