Skip to main content

Crate websearch

Crate websearch 

Source
Expand description

Web search with reference-style URL preservation.

Results reuse the same reference-style URL preservation as the fetch path: each hit’s title carries an inline [N] marker and the full URLs are collected into a reference block, keeping the context window tight while staying citable.

DuckDuckGo Lite is the default backend and needs no key, so the tool works with zero configuration. Because it is scraped HTML it is also the least reliable: types::SearchStatus reports a challenge or unparseable page as a failure instead of an empty result, and providers::Provider offers keyed alternatives for callers who need a real API contract.

Re-exports§

pub use providers::Provider;

Modules§

compress
extract
Parse DuckDuckGo Lite’s table layout into structured results, and tell a real results page apart from a bot challenge.
http
HTTP primitives shared by the fetch and search paths: the user agent, the response-body cap, and the retry classification. Both paths previously carried their own copy of the last two and had drifted apart — search read bodies without any cap at all.
providers
Search backends.
refs
Shared reference-style URL preservation.
tls
Shared TLS trust configuration for the HTTP clients.
types
Types for the web-search layer.

Functions§

build_output
Assemble an output from parsed results.
build_output_from_ddg
Parse an already-fetched DuckDuckGo Lite page into a SearchOutput (no network). Kept for tests and offline callers.
build_refs
Build the reference block (index → URL) from parsed results.
format_results
Render the inline body: each result as title [N] followed by its snippet. URLs are intentionally absent here — they live in the reference block.
render_output
Render the human-readable form of a search: results, then the reference block, then a one-line note when the search did not actually answer.
render_references
Render the reference block appended to text output. Thin wrapper over crate::refs::render_block.
run_search
Run a query against the configured provider, falling back to options.fallback when the primary errors or is blocked.
status_note
A plain-language explanation of a non-Ok status. None when results came back normally.