Lightweight Search Engine

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:

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

System Requirements

Required

Optional

Verify Your Setup

hugo version              # Check Hugo installation
php -v                    # Check PHP version
php -m | grep sqlite3     # Verify SQLite extension

Key Features

Learn More

Tutorials and Guides

Visit our blog for in-depth tutorials:

Performance

Get Help


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:

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)

ParameterTypeRequiredDefaultDescription
qstringYes-Search query (minimum 2 characters)
pageintegerNo1Page number for pagination (1-indexed)
sectionstringNo-Filter results by section (e.g., “blog”, “docs”)
sortstringNorelevanceSort order: relevance, date_desc, or date_asc
limitintegerNo20Results per page (maximum 100)

Sections Action

ParameterTypeRequiredDescription
actionstringYesSet 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 -}}
]

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:

To use this in your site, simply copy these files from the repository to your Hugo site.