Algolia Search Integration
This documentation site uses Algolia DocSearch for fast keyword search, plus Ask AI for conversational answers.
Features
- Fast, relevant search: Algolia returns results in milliseconds.
- Ask AI: Conversational answers based on indexed documentation content.
- Contextual filtering: Results are filtered by docs metadata.
- Keyboard shortcuts: Press
Ctrl+K(orCmd+Kon macOS) to open search. - API-based indexing: Content is pushed directly via API instead of crawler-based indexing.
- Dark mode support: Search UI follows site theme.
How It Works
We maintain two Algolia indexes, each serving a different purpose:
| Index | Purpose | Records |
|---|---|---|
PacingDocs1Index | Keyword search with per-heading records and hierarchy | ~2,800 |
PacingDocs1Index-markdown | Ask AI context with one full-page record per document | ~200 |
Indexing Process
- Build time:
npm run buildtriggers thepostbuildhook, which runsindex-algolia.cjs. - Keyword index: Built HTML is split into heading-based records and pushed to
PacingDocs1Index. - Markdown index: The same HTML is converted into one full-page text record per page and pushed to
PacingDocs1Index-markdown. - Index settings: Applied during indexing, so manual dashboard reconfiguration is minimal.
This works even though production is protected by Cloudflare Access, because indexing uses API push from build output.
Why Two Indexes?
The keyword index (PacingDocs1Index) is excellent for fast section-level retrieval.
The markdown index (PacingDocs1Index-markdown) provides whole-page context (up to 100 KB text per record), improving Ask AI answer quality.
Configuration
Environment Variables
Use environment variables for values that should vary by environment, especially secrets:
# Algolia configuration
ALGOLIA_APP_ID=your-app-id
ALGOLIA_SEARCH_API_KEY=your-search-only-key
ALGOLIA_ADMIN_API_KEY=your-admin-api-key
ALGOLIA_INDEX_NAME=PacingDocs1Index
Security notes:
ALGOLIA_SEARCH_API_KEYis public/search-only.ALGOLIA_ADMIN_API_KEYis secret and must never be committed.
Assistant ID note:
- Ask AI
assistantIdis currently set indocusaurus.config.ts. - If you want env-based configuration, update code to read
ALGOLIA_ASSISTANT_IDexplicitly.
Local development: Store variables in .env at the docusaurus/ root (gitignored).
Production: Set variables in Cloudflare Pages environment settings.
Docusaurus Config
Current config in docusaurus.config.ts:
algolia: {
appId: 'OMNGM7GBAZ',
apiKey: 'your-search-only-key',
indexName: 'PacingDocs1Index',
contextualSearch: true,
searchParameters: { hitsPerPage: 20 },
askAi: {
indexName: 'PacingDocs1Index-markdown',
apiKey: 'your-search-only-key',
appId: 'OMNGM7GBAZ',
assistantId: 'your-assistant-id',
},
searchPagePath: 'search',
},
Using Search
Basic Search
- Open search via the navbar or
Ctrl+K/Cmd+K. - Type your query.
- Navigate with arrow keys, press Enter to open.
- Click "See all results" for the dedicated search page.
Ask AI
- Open search.
- Switch to the Ask AI tab.
- Ask a natural-language question.
- Review the answer and open cited source pages.
Search Tips
- Use specific phrases (
GTM server-side trackinginstead oftracking). - Try alternate terms if no good results appear.
- Use section context and filters when narrowing results.
Manual Indexing
To re-run indexing without a full rebuild:
cd docusaurus
npm run index-algolia
Useful when:
- testing indexing changes
- recovering from a failed postbuild index step
- validating fresh content in both indexes
Troubleshooting
Search Returns No Results
Possible causes:
- no records indexed yet
- index was cleared
- query too narrow
Solution:
- Confirm records exist in Algolia.
- Run
npm run index-algolia. - Verify environment variables.
Ask AI Not Working
Possible causes:
- markdown index is empty
- wrong Ask AI assistant configuration
- API/network failures
Solution:
- Run
npm run index-algoliato repopulate both indexes. - Verify
assistantIdindocusaurus.config.ts. - Confirm Ask AI is enabled in Algolia.
- Check browser console/network logs.
Indexing Fails in Production
Possible causes:
- missing
ALGOLIA_ADMIN_API_KEY - transient network failure during build
- build output not available
Solution:
- Check Cloudflare Pages environment variables.
- Review build logs.
- Confirm
postbuildexecutes successfully.
Stale Search Results
Possible causes:
- latest deploy not completed
- browser cache
- stale index contents
Solution:
- Wait for deploy completion.
- Refresh with cache bypass.
- Trigger manual reindex if needed.
Index Configuration
Keyword Index (PacingDocs1Index)
Per-heading records with hierarchy fields (lvl0 to lvl3) and content-focused ranking.
{
searchableAttributes: [
'unordered(hierarchy.lvl0)',
'unordered(hierarchy.lvl1)',
'unordered(hierarchy.lvl2)',
'unordered(hierarchy.lvl3)',
'content',
],
attributesForFaceting: [
'filterOnly(type)',
'filterOnly(lang)',
'filterOnly(language)',
'filterOnly(version)',
'filterOnly(docusaurus_tag)',
],
}
Markdown Index (PacingDocs1Index-markdown)
One full-text record per page for Ask AI context retrieval.
{
searchableAttributes: ['title', 'heading', 'unordered(text)'],
attributesForFaceting: [
'filterOnly(lang)',
'filterOnly(language)',
'filterOnly(version)',
'filterOnly(docusaurus_tag)',
'filterOnly(type)',
],
ignorePlurals: true,
typoTolerance: false,
}
Security Notes
- Search keys are public/search-only by design.
- Admin keys are secret and must be stored only in secure environment configuration.
- Do not paste real credentials into docs examples.