doc:gen-index
Generate search index from documentation content
doc:gen-index
The doc:gen-index command generates a full-text search index from your documentation. It extracts titles, descriptions, headings, and content to enable fast, relevant searching.
Command Syntax
php artisan doc:gen-indexWhat It Does
The command performs these operations:
- Loads navigation structure - Reads the generated navigation.json
- Iterates all pages - Processes every page in the documentation
- Extracts content - Pulls title, description, content, and headings
- Calculates scores - Assigns relevance weights to different elements
- Generates index - Creates search-index.json with all searchable content
Running the Command
Basic usage:
php artisan doc:gen-indexOutput:
Generating search index...
Processing documentation pages...
ā 12 pages indexed
ā Search index generated: resources/markdown/docs/search-index.json
Generated search-index.json
The command creates resources/markdown/docs/search-index.json:
{
"documents": [
{
"id": "getting-started",
"title": "Getting Started",
"section": "Getting Started",
"description": "Installation and setup guide",
"url": "/documentation/getting-started",
"content": "OI Laravel Documentation is a comprehensive package...",
"headings": [
"What You Get",
"Requirements",
"Quick Start"
],
"score": 0
},
{
"id": "installation",
"title": "Installation",
"section": "Getting Started",
"description": "Step-by-step installation and setup guide",
"url": "/documentation/getting-started/installation",
"content": "Follow these steps to install and configure...",
"headings": [
"Step 1: Install the Package",
"Step 2: Run the Installation Wizard",
"Step 3: Register Routes"
],
"score": 0
}
]
}Search Index Structure
Document Fields
Each searchable document in the index contains:
| Field | Type | Purpose |
|---|---|---|
id | string | Unique page identifier |
title | string | Page title from frontmatter |
section | string | Section name |
description | string | Page description |
url | string | Full documentation URL |
content | string | Plain text page content |
headings | array | All heading text from page |
score | number | Search relevance (calculated at query time) |
Search Scoring Algorithm
When a user searches, the package scores documents based on where matches occur. Higher scores appear first:
Title match ā +10 points per match
Description match ā +5 points per match
Heading match ā +3 points per match
Content match ā +1 point per match
Scoring Example
Searching for "installation":
Page: "Installation Guide"
- Title contains "installation" ā +10
- Description "...installation steps..." ā +5
- Heading "Step 1: Installation" ā +3
- Content mentions "installation" 8 times ā +8
Total Score: 26 points
Another page with "installation" only in content (5 mentions):
Total Score: 5 points
The first page ranks higher due to the title and description matches.
When to Regenerate
Run this command when you:
- Change page content - Update markdown content
- Update page titles - Change frontmatter title
- Modify descriptions - Update frontmatter description
- Add new pages - Create new documentation files
- Delete pages - Remove documentation files
- Change headings - Update heading text in content
Typically after any content changes.
Workflow: Updating Documentation
-
Edit markdown file:
bash# Edit docs/guides/getting-started.md -
Regenerate search index:
bashphp artisan doc:gen-index -
Changes are now searchable immediately
Search Index Output Location
The command outputs to:
resources/markdown/docs/search-index.json
Configured in config/oi-documentation.php:
'search_index_file' => 'search-index.json',Change if needed:
'search_index_file' => 'custom-index.json',Search Behavior
Minimum Query Length
Controlled by configuration:
'search' => [
'min_query_length' => 2, // Require at least 2 characters
],Set in config/oi-documentation.php.
Excerpt Generation
When returning results, excerpts are generated with context:
'search' => [
'excerpt_length' => 150, // Show 150 characters
'excerpt_context' => 50, // 50 chars before/after match
],Example result:
"...installation wizard that guides you through configuration:
1. **Publish the configuration file** to `config/oi-documentation.php`
2. **Prompt for middleware settings**..."
Troubleshooting
Search Index is Empty
Verify:
-
Navigation has been generated:
bashphp artisan doc:gen-nav -
Markdown files exist with valid frontmatter:
yaml--- title: Page Title --- -
Try regenerating with verbose output:
bashphp artisan doc:gen-index --verbose
Missing Pages in Search
Check:
- Page has a title in frontmatter
- Page is in navigation (run
doc:gen-navfirst) - Run
doc:gen-indexagain
Stale Search Results
The index is static. After content changes, regenerate:
php artisan doc:gen-indexOr combine commands:
php artisan doc:gen-nav && php artisan doc:gen-indexSearch Not Finding Content
Ensure:
- Search query is at least 2 characters
- Index has been regenerated recently
- Content contains the search terms
Check config/oi-documentation.php search settings.
Automation
Run in CI/CD pipelines:
# Build documentation in CI
php artisan doc:gen-nav
php artisan doc:gen-indexOr create a single command:
# Make a custom command
php artisan make:command RegenerateDocs// app/Console/Commands/RegenerateDocs.php
public function handle()
{
$this->call('doc:gen-nav');
$this->call('doc:gen-index');
$this->info('Documentation regenerated!');
}Then use:
php artisan regenerate-docsIntegration with Content Generation
When using doc:add-page --regenerate:
php artisan doc:add-page --regenerateThis automatically regenerates both navigation and search index.
Performance
For large documentation sets:
- Index generation: Fast (< 1 second for 1000+ pages)
- Index size: ~1-2MB for typical documentation
- Search performance: Instant (client-side)
Important Notes
Never manually edit search-index.json ā It's regenerated by the command. Manual edits are lost on next regeneration.
Use markdown content and frontmatter to control what's searchable.
Complete Workflow
For a complete documentation update:
# 1. Add/edit markdown files
# 2. Regenerate navigation
php artisan doc:gen-nav
# 3. Regenerate search index
php artisan doc:gen-index
# 4. Rebuild front-end assets
npm run build
# 5. Visit documentation
# Changes are now live!Or use a combined command:
php artisan doc:gen-nav && php artisan doc:gen-index && npm run buildNext Steps
After generating the search index:
- Test Search - Test the search functionality
- View Documentation - Visit your docs
- Monitor Updates - Keep docs current