Typesense Search - Proof of Concept
What Has Been Done
I've set up a complete Typesense search integration for your Docusaurus site. Here's what's been configured:
✅ Completed Setup
-
Dependencies Installed
docusaurus-theme-search-typesense- Docusaurus theme for Typesensetypesense- Typesense client library
-
Docker Configuration
docker-compose.yml- Docker Compose file for local Typesense server- Configured to run on
http://localhost:8108 - Uses API key:
mambu_docs_search_key
-
Indexing Script
scripts/index-to-typesense.js- Complete indexing solution- Automatically parses all
.mdand.mdxfiles - Extracts frontmatter, content, and headings
- Detects content types (User Guide, API v2, API v1, etc.)
- Creates weighted search schema
-
Docusaurus Configuration
- Updated
docusaurus.config.tsto use Typesense theme - Commented out old search plugin
- Configured search parameters with field weights
- Updated
-
NPM Scripts
npm run typesense:start- Start Typesense servernpm run typesense:stop- Stop Typesense servernpm run typesense:index- Index all documentationnpm run typesense:setup- One-command setup
How to Test
Step 1: Start Docker
First, make sure Docker Desktop is running on your Mac:
open -a Docker
Wait for Docker to start completely (check the Docker icon in the menu bar).
Step 2: Start Typesense Server
npm run typesense:start
Verify it's running:
curl http://localhost:8108/health
Should return: {"ok":true}
Step 3: Index Your Documentation
npm run typesense:index
This will:
- Scan all documentation files
- Parse content and metadata
- Create search records
- Upload to Typesense
You should see output like:
🚀 Starting Typesense indexing...
✅ Created new collection with schema
📂 Scanning for documentation files...
Found 250 files
✅ Parsed 245 documents (5 skipped)
📦 Batch 1: 100 indexed, 0 failed
📦 Batch 2: 100 indexed, 0 failed
📦 Batch 3: 45 indexed, 0 failed
✨ Indexing complete!
📊 Total documents indexed: 245
Step 4: Start Docusaurus
npm run clear
npm run start
Step 5: Test Search
- Open
http://localhost:3000 - Click the search box or press
Cmd+K - Try these test queries:
- "deposit account"
- "create loan"
- "transaction"
- "payment channel"
What to Look For
🎯 Search Quality Indicators
Relevance:
- Most relevant results should appear first
- Title matches should rank higher than content matches
- User Guide results should appear before API docs (when relevant)
Context:
- Each result shows a description/preview
- You can see the content type (User Guide, API v2, etc.)
- Full path/breadcrumb is visible
Speed:
- Results should appear instantly (under 100ms)
- No lag or delay while typing
Features:
- Typo tolerance: Try "deposite" or "acconut"
- Partial matching: Try "depo" or "trans"
- Multi-word queries: Try "create deposit account"
📊 Comparing with Current Search
Compare these aspects:
| Aspect | Current Search | Typesense |
|---|---|---|
| Speed | ? | < 100ms |
| Relevance | ? | Weighted ranking |
| Typo tolerance | ? | Built-in |
| Context | 150 chars | Customizable |
| Grouping | Manual JS | Native sorting |
| Performance | Client-side | Server-side |
Search Configuration
Field Weights
The search is configured with these weights:
query_by: 'title,description,content,headings'
query_by_weights: '4,3,1,2'
This means:
- Title (4x) - Highest priority
- Description (3x) - High priority
- Headings (2x) - Medium priority
- Content (1x) - Base priority
Content Type Priority
Results are sorted by content type priority:
- User Guide (priority: 1)
- API v2 Reference (priority: 2)
- API v1 Reference (priority: 3)
- Streaming API (priority: 4)
- Functions API (priority: 5)
- Payments API (priority: 6)
- Other Documentation (priority: 7)
Troubleshooting
Docker Not Running
Error: cannot connect to docker daemon
Solution:
open -a Docker
# Wait for Docker to start, then retry
npm run typesense:start
Port Already in Use
Error: port 8108 is already allocated
Solution:
# Find what's using the port
lsof -i :8108
# Stop existing Typesense container
docker stop mambu-docs-typesense
docker rm mambu-docs-typesense
# Start again
npm run typesense:start
Indexing Fails
Error: Connection refused or ECONNREFUSED
Solution:
-
Make sure Typesense is running:
curl http://localhost:8108/health -
Check container logs:
docker logs mambu-docs-typesense -
Restart Typesense:
npm run typesense:stop
npm run typesense:start
sleep 3
npm run typesense:index
Search Not Working
Error: Search box doesn't show results
Solution:
-
Check browser console for errors
-
Verify collection exists:
curl http://localhost:8108/collections/mambu_docs \
-H "X-TYPESENSE-API-KEY: mambu_docs_search_key" -
Test search directly:
curl "http://localhost:8108/collections/mambu_docs/documents/search?q=deposit&query_by=title" \
-H "X-TYPESENSE-API-KEY: mambu_docs_search_key" -
Rebuild Docusaurus:
npm run clear
npm run build
npm run serve
Testing Checklist
Use this checklist to evaluate the search:
- Docker is running
- Typesense server started successfully
- Indexing completed without errors
- Docusaurus builds successfully
- Search box appears on the site
- Simple query returns results (e.g., "deposit")
- Results are relevant to the query
- User Guide results appear first (when applicable)
- Preview text is helpful and contextual
- Typo tolerance works (e.g., "deposite")
- Partial matching works (e.g., "depo")
- Search is fast (< 100ms)
- Results look visually organized
Next Steps After Testing
If Search Quality is Good ✅
-
Customize Result Display
- Enhance visual styling
- Add content type badges/colors
- Improve grouping headers
-
Add Advanced Features
- Faceted search filters (filter by content type)
- Search analytics tracking
- Recent searches
- Search suggestions
-
Plan Production Deployment
- Set up Typesense Cloud or self-hosted server
- Create production API keys
- Set up CI/CD for automatic indexing
- Configure environment variables
If Search Needs Improvement 🔧
-
Adjust Field Weights
- Edit
docusaurus.config.ts - Change
query_by_weightsvalues - Re-test search quality
- Edit
-
Improve Indexing
- Edit
scripts/index-to-typesense.js - Adjust content parsing
- Add more metadata fields
- Improve description extraction
- Edit
-
Fine-tune Ranking
- Adjust content type priorities
- Add boost factors for specific pages
- Implement custom ranking rules
Files Created/Modified
New Files
- ✅
docker-compose.yml- Typesense server configuration - ✅
scripts/index-to-typesense.js- Indexing script - ✅
TYPESENSE_POC.md- This file
Modified Files
- ✅
package.json- Added Typesense scripts - ✅
docusaurus.config.ts- Added Typesense configuration - ✅
.gitignore- Added typesense-data directory
Unchanged (for reference)
SEARCH_SOLUTION.md- Previous search implementationSEARCH_IMPROVEMENTS.md- Previous improvementssrc/client-modules/group-search-results-simple.js- Old grouping logic
Questions to Consider
After testing, think about:
- Is the search faster than the current solution?
- Are results more relevant?
- Does typo tolerance help users?
- Is the preview text more useful?
- Do users benefit from content type ordering?
- Are there any missing features from the old search?
- Is the setup/maintenance complexity worth the improvement?
Resources
- Typesense Documentation
- Search Configuration Reference
- Docusaurus Plugin
- Typesense Cloud - For production
Need Help?
If you encounter issues:
- Check the Troubleshooting section above
- Review the indexing script output for errors
- Test Typesense directly with curl commands
- Check browser console for JavaScript errors
- Verify Docker is running and container is healthy
Ready to test? Start with Docker, then run npm run typesense:setup to get everything running!