Documentation
Hugo SQLite Search Documentation
Welcome to Hugo SQLite Search - a powerful, lightweight search engine for your Hugo static sites. Built with PHP, SQLite FTS5, and a simple JavaScript frontend, it delivers fast, server-side full-text search without complex dependencies.
Overview
Hugo SQLite Search is a complete search solution that:
- Indexes during build - Automatically creates a SQLite FTS5 database from your Hugo content
- Searches server-side - PHP-powered REST API with advanced query capabilities
- Ranks intelligently - BM25 algorithm with field weighting and Porter stemming
- Stays portable - Single SQLite database file, easy to deploy anywhere
- Performs fast - Sub-50ms queries on databases with 1000+ pages
Perfect for blogs, documentation sites, and content-rich Hugo projects of any size.
Documentation Sections
Getting Started
Complete installation guide to get search running on your Hugo site in under 10 minutes. Includes step-by-step setup, build scripts, and deployment instructions.
API Reference
Comprehensive API documentation covering all search endpoints, query parameters, response formats, and advanced search syntax.
Configuration
Learn how to customize search behavior, adjust ranking weights, configure field indexing, and optimize performance for your specific needs.
Examples
Real-world implementation examples including custom search interfaces, section filtering, advanced queries, and integration patterns.
Quick Start
# 1. Copy files to your Hugo site
# 2. Configure Hugo for JSON output
# 3. Run the build script
./build.sh
# 4. Test locally
cd public && php -S localhost:8080
Visit Getting Started for detailed instructions.
Common Tasks
- First-time setup - Follow the Installation guide
- Rebuild search index - Run
./build.shafter content updates - Customize search UI - Edit
/layouts/page/search.htmltemplate - Exclude pages - Add
search: falseto page front matter - Test search API - Use
curlor visit/api/search.php?q=test - Debug issues - Check the Troubleshooting section
System Requirements
Required
- Hugo - Any recent version (Install Hugo)
- PHP 7.4+ - With SQLite3 extension enabled
- Web server - Apache, Nginx, or PHP built-in server
Optional
- SQLite3 CLI - For database debugging and inspection
Verify Your Setup
hugo version # Check Hugo installation
php -v # Check PHP version
php -m | grep sqlite3 # Verify SQLite extension
Key Features
- Porter Stemming - Matches word variants automatically (search “run” finds “running”, “runs”)
- Phrase Search - Exact matching with quoted queries:
"getting started" - Field-Specific Search - Target fields:
title:hugo,tags:tutorial - Date Filtering - Time-based queries:
after:2024-01-01,before:2024-12-31 - Section Filtering - Limit results by content section
- BM25 Ranking - Sophisticated relevance scoring
- Fuzzy Matching - Automatic prefix matching for partial terms
- Boolean Operators - Combine terms with OR logic
Learn More
Tutorials and Guides
Visit our blog for in-depth tutorials:
- Introducing Lightweight Search - Project overview and philosophy
- Search Performance Tips - Optimization strategies
- Building Custom Tokenizers - Advanced customization
Performance
- Build time: ~0.1-0.5 seconds per 100 pages
- Database size: ~50-200 KB per 100 pages
- Query time: <50ms typical for 1000+ page sites
- Memory usage: Minimal - SQLite loads only needed data
Get Help
- Browse the documentation sections above
- Check Troubleshooting for common issues
- Review Examples for implementation patterns
Ready to add search to your Hugo site? Start with Getting Started.
Getting Started
Getting Started
Get Hugo Lightweight Search up and running on your site in under 10 minutes. This guide covers the complete setup of a PHP-powered search engine using Hugo, SQLite FTS5, and a JavaScript frontend.
What You’ll Build
A fast, server-side search engine that:
- Indexes your Hugo content automatically during build
- Uses SQLite FTS5 for powerful full-text search with stemming
- Provides a REST API for searching
- Includes a ready-to-use search page with JavaScript client
Prerequisites
Before you begin, ensure you have:
API Reference
API Reference
Complete reference for the Hugo Lightweight Search PHP API.
Endpoint
GET /api/search.php
Base URL: https://yourdomain.com/api/search.php
Authentication
The API is publicly accessible and does not require authentication. CORS is enabled to allow cross-origin requests.
Query Parameters
Search Action (Default)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
q | string | Yes | - | Search query (minimum 2 characters) |
page | integer | No | 1 | Page number for pagination (1-indexed) |
section | string | No | - | Filter results by section (e.g., “blog”, “docs”) |
sort | string | No | relevance | Sort order: relevance, date_desc, or date_asc |
limit | integer | No | 20 | Results per page (maximum 100) |
Sections Action
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | Yes | Set to sections to retrieve available sections |
Advanced Query Syntax
The search API supports advanced query operators for precise searching:
Configuration
Configuration
Customize Hugo SQLite Search to match your site’s needs.
Hugo Configuration
Required: JSON Output
Enable JSON output in your hugo.yaml:
outputs:
home:
- HTML
- RSS
- JSON
outputFormats:
JSON:
baseName: index
isPlainText: true
mediaType: application/json
notAlternative: true
JSON Template Configuration
The search data template (layouts/_default/search-data.json) controls what content gets indexed.
Default Template
{{- $pages := where site.RegularPages "Type" "!=" "page" -}}
{{- $pages = where $pages "Draft" "!=" true -}}
{{- $pages = where $pages "Params.search" "!=" false -}}
[
{{- range $index, $page := $pages -}}
{{- if $index }},{{ end }}
{
"id": {{ $page.File.UniqueID | jsonify }},
"title": {{ $page.Title | jsonify }},
"url": {{ $page.Permalink | jsonify }},
"content": {{ $page.Plain | jsonify }},
"summary": {{ $page.Summary | jsonify }},
"date": {{ $page.Date.Format "2006-01-02" | jsonify }},
"section": {{ $page.Section | jsonify }},
"tags": {{ $page.Params.tags | jsonify }},
"categories": {{ $page.Params.categories | jsonify }}
}
{{- end -}}
]
Exclude Pages from Search
Add to page front matter:
Examples
Examples
Real-world examples of implementing Hugo SQLite Search in various scenarios. All source code is available in the GitHub repository.
Hugo Integration Examples
1. Complete Working Search Page
The repository includes a fully functional search page implementation:
- Content file:
content/pages/search.mddefines the search page - Template:
layouts/page/search.htmlcontains the complete search UI and JavaScript client - Live demo: Try it here
To use this in your site, simply copy these files from the repository to your Hugo site.