M3: search — SearXNG container, searcher service, orchestrator /search
- searcher: file-based instance list (mtime-reloaded, hand-editable), failover across instances, URL normalization + dedup, Redis search cache (300s TTL) - searxng: pinned settings.yml with JSON format enabled and limiter disabled, secret from SEARXNG_SECRET env; wired into compose with config volume - orchestrator: /search proxying the searcher with per-stage trace; searcher included in aggregated /health Verified against a mock SearXNG: failover past a dead instance, dedup of trailing-slash duplicates, non-http URL filtering, cache miss/hit flags. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
56e7fa16dd
commit
53f0d50e7a
10 changed files with 298 additions and 1 deletions
|
|
@ -29,12 +29,21 @@ class ScrapeRequest(BaseModel):
|
|||
url: str
|
||||
|
||||
|
||||
class SearchRequest(BaseModel):
|
||||
query: str
|
||||
max_results: int = 10
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health() -> dict:
|
||||
"""Aggregate health across all downstream services."""
|
||||
client: httpx.AsyncClient = app.state.client
|
||||
services = {}
|
||||
for name, base in [("renderer", config.RENDERER_URL), ("extractor", config.EXTRACTOR_URL)]:
|
||||
for name, base in [
|
||||
("searcher", config.SEARCHER_URL),
|
||||
("renderer", config.RENDERER_URL),
|
||||
("extractor", config.EXTRACTOR_URL),
|
||||
]:
|
||||
try:
|
||||
resp = await client.get(f"{base}/health", timeout=5)
|
||||
services[name] = resp.json() if resp.status_code == 200 else {"status": "error"}
|
||||
|
|
@ -49,6 +58,17 @@ async def health() -> dict:
|
|||
}
|
||||
|
||||
|
||||
@app.post("/search")
|
||||
async def search(req: SearchRequest) -> dict:
|
||||
trace = pipeline.Trace()
|
||||
try:
|
||||
results = await pipeline.search(app.state.client, req.query, req.max_results, trace)
|
||||
except pipeline.StageError as exc:
|
||||
log.error("search failed: %s", exc.detail)
|
||||
raise HTTPException(status_code=502, detail={"stage": exc.stage, "error": exc.detail}) from exc
|
||||
return {"results": results, "trace": trace.as_dict()}
|
||||
|
||||
|
||||
@app.post("/scrape")
|
||||
async def scrape(req: ScrapeRequest) -> dict:
|
||||
if not req.url.startswith(("http://", "https://")):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue