Configure search
DevDocify uses Algolia for contextual search across docsets. The site config exposes a search-only API key to the browser, while CI can push a structured index that includes both documentation pages and API operations.
Prerequisites
- An Algolia application and index.
- Access to
docusaurus.config.ts. - A deployed docs URL for production search.
- An
ALGOLIA_ADMIN_API_KEYCI secret if you want deploy-time index pushes.
1. Configure browser search
In docusaurus.config.ts, confirm that themeConfig.algolia contains these values:
algolia: {
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indexName: 'YOUR_INDEX_NAME',
contextualSearch: true,
},
Use a search-only API key for apiKey. Do not expose an admin key in source code or browser bundles.
2. Build the structured index
Generate the local search index:
npm run build-search-index
The command writes build/search-index.json. The index contains:
| Type | Source |
|---|---|
doc | Markdown and MDX pages from each docset |
api-op | OpenAPI operations from static/openapi/*.json |
The npm run build command also runs this step through postbuild.
3. Test the Algolia payload locally
Build the site and run a dry push:
npm run build
npm run push-search-index -- --dry-run
The dry run prints record counts by docset and a sample Algolia record. It does not call the Algolia API.
4. Add CI credentials
Add ALGOLIA_ADMIN_API_KEY as a GitHub Actions secret. The CI workflow uses it only on pushes to main.
Optional environment variables:
| Variable | Purpose |
|---|---|
ALGOLIA_APP_ID | Overrides the app ID from the script default. |
ALGOLIA_INDEX_NAME | Overrides the default devdocify index name. |
If ALGOLIA_ADMIN_API_KEY is absent, the push job exits successfully without updating Algolia. This keeps forks and local preview branches from failing because they do not have production secrets.
5. Verify contextual results
After deployment, test search from at least two docsets:
- Open
/docsand search for a DevDocify topic. - Open
/tfl/getting-startedand search for a TfL topic. - Confirm that results stay scoped to the current docset when contextual search is active.
Troubleshooting
- No browser search box: confirm
themeConfig.algoliais present indocusaurus.config.ts. - No results after deploy: confirm
ALGOLIA_ADMIN_API_KEYexists and the push job ran onmain. - Cross-docset results appear: confirm
contextualSearch: trueandfilterOnly(docset)faceting inscripts/push-search-index.ts. - API operations are missing: confirm the relevant OpenAPI file exists in
static/openapi/and rerunnpm run build-search-index.