Add time_range filter to Research Bridge API and optimize SearXNG config for news

This commit is contained in:
Henry
2026-03-14 13:41:20 +00:00
parent 561e655a67
commit c0d6e72d7c
4 changed files with 67 additions and 6 deletions

View File

@@ -18,28 +18,81 @@ search:
- json
engines:
# === General Search ===
- name: google
engine: google
shortcut: go
disabled: false
weight: 1.0
- name: bing
engine: bing
shortcut: bi
disabled: false
weight: 1.0
- name: duckduckgo
engine: duckduckgo
shortcut: ddg
disabled: false
weight: 0.8
# === News Engines ===
- name: google news
engine: google_news
shortcut: gon
disabled: false
weight: 2.0
- name: bing news
engine: bing_news
shortcut: bin
disabled: false
weight: 2.0
- name: hackernews
engine: hackernews
shortcut: hn
disabled: false
weight: 1.5
# === Tech News ===
- name: arstechnica
engine: arstechnica
shortcut: ars
disabled: false
weight: 1.5
- name: wired
engine: wired
shortcut: wir
disabled: false
weight: 1.5
# === Q&A / Discussion ===
- name: reddit
engine: reddit
shortcut: re
disabled: false
weight: 1.2
# Block unwanted sites (dictionaries, etc.)
engines:
- name: google
engine: google
disabled: false
url_xpath: //
# Blocklist für unerwünschte Domains
# Auskommentiert da SearXNG keine native Blocklist hat
# Workaround: Zeit-Parameter in Queries nutzen
ui:
static_path: ""
static_static_path: ""
templates_path: ""
default_theme: simple
query_in_title: true
# Time range preference (for news queries)
# Note: Used by engines that support it (google, bing, etc.)
# Valid values: day, week, month, year

View File

@@ -53,7 +53,8 @@ async def search(
default=["google", "bing", "duckduckgo"],
description="Search engines to use"
),
page: int = Query(default=1, ge=1, description="Page number")
page: int = Query(default=1, ge=1, description="Page number"),
time_range: str | None = Query(default=None, pattern="^(day|week|month|year)$", description="Time filter (day, week, month, year)")
) -> SearchResponse:
"""Search via SearXNG (passthrough).
@@ -61,6 +62,7 @@ async def search(
q: Search query string
engines: List of search engines
page: Page number
time_range: Optional time filter
Returns:
SearchResponse with results
@@ -69,7 +71,7 @@ async def search(
async with SearXNGClient(base_url=SEARXNG_URL) as client:
try:
return await client.search(request)
return await client.search(request, time_range=time_range)
except SearXNGError as e:
raise HTTPException(status_code=502, detail=str(e))
@@ -120,10 +122,10 @@ async def research(request: ResearchRequest) -> ResearchResponse:
page=1
)
# Execute search
# Execute search with time_range if specified
async with SearXNGClient(base_url=SEARXNG_URL) as client:
try:
search_response = await client.search(search_request)
search_response = await client.search(search_request, time_range=request.time_range)
except SearXNGError as e:
raise HTTPException(status_code=502, detail=str(e))

View File

@@ -67,6 +67,7 @@ class ResearchRequest(BaseModel):
sources: list[str] = Field(default=["web"])
language: str = Field(default="en", pattern="^[a-z]{2}$")
omit_raw: bool = Field(default=False)
time_range: str | None = Field(default=None, pattern="^(day|week|month|year)$", description="Time filter for search results")
class Source(BaseModel):

View File

@@ -59,11 +59,12 @@ class SearXNGClient:
query_string = "&".join(query_parts)
return f"{self.base_url}/search?{query_string}"
async def search(self, request: SearchRequest) -> SearchResponse:
async def search(self, request: SearchRequest, time_range: str | None = None) -> SearchResponse:
"""Execute search query against SearXNG.
Args:
request: SearchRequest with query, engines, page
time_range: Optional time filter (day, week, month, year)
Returns:
SearchResponse with results
@@ -77,6 +78,10 @@ class SearXNGClient:
"engines": ",".join(request.engines),
"pageno": request.page,
}
# Add time_range if specified (SearXNG supports: day, week, month, year)
if time_range:
params["time_range"] = time_range
url = self._build_url(params)
client = self._get_client()