Skip to main content

sphinx-searchlite

Client-side documentation search for any Sphinx theme. No search service, no runtime dependency, no build step beyond Sphinx itself.

extensions = ["sphinx_searchlite"]

That is the whole setup. A ⌘K / / dialog appears on every page, backed by a JSON index emitted next to the build.

Why not Sphinx's own search?

Sphinx ships searchindex.js, but it is coupled to searchtools.js and to the dedicated search.html page. There is no supported way to query it from your own UI. sphinx-searchlite emits plain records instead, so a theme can render results however it likes.

Ranking

Results are scored with BM25 over two fields:

  • the record's own heading, boosted heavily
  • the title of the page it belongs to, boosted lightly

The distinction matters. Boosting both together makes every section of a page inherit that page's relevance, so searching for a page title surfaces its subsections above the page itself.

The word you are still typing is matched as a prefix in addition to an exact match, so install also reaches installation. All query words must match, so extra words narrow the result set.

Configuration

Option Default Description
searchlite_index_filename searchlite-index.json Written to _static/.
searchlite_max_text 1200 Characters of body text kept per record.
searchlite_ui True Ship the bundled dialog. Set False to supply your own.
searchlite_adopt_theme_search True Rebind the theme's own search box to the dialog. Set False to leave it alone.

Working with an existing theme

Most themes already render a search box wired to Sphinx's search.html. Left alone that gives a page two different searches, and the dialog has no visible trigger of its own. By default searchlite takes that box over: it is made read-only, and focusing, clicking, or submitting it opens the dialog instead.

The dialog also adopts the page's own colours, so it follows a theme's light/dark toggle rather than the prefers-color-scheme media query — themes typically switch on a class or attribute, which that query does not track.

Driving it yourself

Set searchlite_ui = False and use the engine directly:

const engine = SearchLite.create({ url: SearchLite.indexUrl });

await engine.load();
const { items, terms } = engine.search("query");

Each item is { u, t, s, x } — url, page title, section heading, text. terms includes prefix expansions, so it can be passed to the bundled SearchLite.highlight(text, terms) and SearchLite.excerpt(record, terms) helpers.

Add data-searchlite-open to any element to make it a trigger.

Styling

The bundled dialog reads --searchlite-* custom properties, so a theme can recolour it without overriding rules:

:root {
  --searchlite-background: #111;
  --searchlite-border: #333;
}

--searchlite-muted, --searchlite-border, and --searchlite-accent are derived from --searchlite-foreground, so setting the background and foreground pair is usually enough. Note that the adopted page colours are set on the dialog element itself and so win over :root; style #searchlite-dialog directly to override them.

Licence

Apache-2.0.

Release files for sphinx-searchlite 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-searchlite 0.2.0
File Size Uploaded
sphinx_searchlite-0.2.0.tar.gz 16.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-searchlite 0.2.0
File Interpreter ABI Platform
sphinx_searchlite-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.2 kB

Release files / sphinx_searchlite-0.2.0.tar.gz

Download URL sphinx_searchlite-0.2.0.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
74b82fd6461383c03f108825f2d03047ae500207009532c1155a5a91aa72e718
BLAKE2b-256 checksum
How to use checksums
588324676886f88bdfd919cbf247d5a80e588e66f8f6fd314e874a7c8f4a6d12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / sphinx_searchlite-0.2.0-py3-none-any.whl

Download URL sphinx_searchlite-0.2.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2631b2cb04518ab930ab0fcce76ce2ed589189640ffc868e41bcf89c263a89a2
BLAKE2b-256 checksum
How to use checksums
bceee82202113f1dd5eb49493bed58ce4c40bb93c39d2f6e2c232aa0646e9bee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page