Search Configuration
This page is the configuration reference for search: the config blocks of the three engines (Local / Algolia / Pagefind), how the default engine is chosen and switched, and multi-language result filtering with unified highlighting. For usage steps (opening the popup, shortcuts) see Layout & Search.
The authoritative source is the
searchblock inuserConfig/_config.tmp.yml, injected into the theme config at build time.
1. Engine Overview
| Engine | Config key | Index |
|---|---|---|
| Local | search.local | /search.json (generated by theme generator) |
| Algolia | search.algolia | remote index (pushed at build time) |
| Pagefind | search.pagefind | public/pagefind/ (scanned after build) |
2. Default Engine & Switching
search.default: one oflocal/algolia/pagefind.- Resolution order:
localStorage['search_engine']→search.default→ Algolia → first enabled engine. - If the default engine has
enable: false, it degrades to the first enabled engine and logs a warning. - Switch entry: the engine dropdown inside the search popup (
#searchEngineMenu, itemsdata-engine=local|algolia|pagefind); switchingdestroys the old engine andinits the new one, and persists tolocalStorage.
3. Local Search search.local
| Key | Description |
|---|---|
enable | Master switch |
path | Index output path, default /search.json |
field | Scope: post / page / wiki / all, or an array |
content | Index body text (false = titles only) |
format | striptags (strip HTML) or raw |
trigger | auto (search as you type) or manual (Enter/button) |
top_n_per_article | Max hit snippets per article, -1 = all |
unescape / preload | Reserved; not wired up yet |
4. Algolia search.algolia
enable/applicationID/apiKey/indexName: switch and credentials (the search key is safe to expose).content_length: body text truncation;excerpt_length: excerpt truncation.batch_size: push batch size;hits.per_page: results per page.labels.*:input_placeholder/hits_empty/hits_stats.- Write key is separated from the frontend key:
deploy.algolia_write_keyis build-only and never injected.
5. Pagefind search.pagefind
enable: master switch.output_subdir: index subdirectory (relative topublic/), defaultpagefind.- Build step: after
hexo generate, before deploy, runnpx pagefind --site public --output-subdir pagefind. - Encrypted posts are excluded automatically via conditional
data-pagefind-bodyrendering.
6. Multi-language & Highlighting
- Filtering:
applyLangFilter→groupAndFilterinsearch.js, grouping by the path’s language prefix. - Preference: read from
localStorage['wiki_lang'], falling back to the default language. - Display priority: preferred language → default language → first hit.
- Highlighting: all three engines share
SearchEngine._highlight, wrapping hits in<mark>with HTML escaping (XSS-safe).