Search Functionality
WharfDocs includes a powerful built-in search feature that helps users quickly find the information they need.
#How Search Works
The search system automatically:
- Indexes all documentation on page load
- Searches through titles, headings, and content
- Ranks results by relevance
- Highlights matching terms in search results
#Search Indexing
When the documentation engine initializes, it:
- Scans all Markdown files in the
docs/directory - Extracts titles, headings, and content
- Creates a searchable index in memory
- Removes Markdown syntax for clean text search
#Search Algorithm
The search algorithm prioritizes results based on:
- Title matches (highest priority - 100 points)
- Heading matches (medium priority - 50 points per match)
- Content matches (10 points per occurrence)
Results are sorted by score and limited to the top 10 matches.
#Using Search
#From the UI
- Click the search box in the header
- Type your query (minimum 2 characters)
- Results appear in real-time as you type
- Click any result to navigate to that page
#Search Tips
- Be specific: More specific queries return better results
- Use keywords: Search for important terms from your topic
- Try variations: If you don't find what you need, try different words
- Check spelling: Typos won't match content
#API Endpoint
Search is also available via API:
GET /api/search?q=your+query
Response format:
[
{
"path": "getting-started/introduction",
"title": "Introduction",
"excerpt": "Welcome to <mark>WharfDocs</mark>...",
"score": 150
}
]
#Customizing Search
You can customize search behavior by modifying src/SearchIndexer.php:
// Change result limit
return array_slice($results, 0, 20); // Show 20 results
// Adjust scoring weights
if (stripos($titleLower, $query) !== false) {
$score += 200; // Increase title match weight
}
#Performance Considerations
- Index is built on initialization: First page load may be slightly slower
- Search is performed in-memory: Very fast for small to medium documentation sites
- No database required: Keeps the system simple and portable
#Future Enhancements
Potential improvements for search:
- Fuzzy matching for typo tolerance
- Search suggestions and autocomplete
- Filter by section or category
- Search history
- Advanced search operators