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.Reading guide: every section follows 「How to enable → Common options → All tunable keys → Boundaries & conflicts」 — check the Effect first, then the Corresponding config that produces it, and copy it to use.
1. Engine Overview
Purpose: know which three indexes exist, and where each one’s artifacts land.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
1.1 How to enable
Effect: once the search popup is open, typing a keyword shows results; the popup also has an engine dropdown for on-the-spot switching, and all three engines share the same result-page layout.
Corresponding config (minimal setup, all three enabled):
search:
default: "algolia"
algolia:
enable: true
local:
enable: true
pagefind:
enable: true1.2 Common options
| Engine | Config key | Index location |
|---|---|---|
| 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) |
① Keep only local search
Effect: no external service is needed; the index ships as an in-site JSON file, but the first search has to download it.
Corresponding config:
search:
default: "local"
local:
enable: true
algolia:
enable: false
pagefind:
enable: false1.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
search.default | string | "algolia" | local / algolia / pagefind | Default engine |
search.local.enable | bool | true | true / false | Local search switch |
search.algolia.enable | bool | true | true / false | Algolia switch |
search.pagefind.enable | bool | true | true / false | Pagefind switch |
1.4 Boundaries & conflicts
- All three can be enabled at once and switched via the dropdown in the popup; disabling an engine removes it from the dropdown.
- Pagefind needs an extra scan after the build (see §5); otherwise that engine has no index.
- Algolia needs the index pushed at build time; credentials are separated as described in §4.
1.5 Summary
- Minimal setup: enable only
local - Want zero services:
localorpagefind - Want relevance/fault tolerance:
algolia - Don’t change only
defaultwithout enabling engines: it degrades automatically
2. Default Engine & Switching
Purpose: decide which engine the popup uses first, and how a reader’s switch is remembered.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
2.1 How to enable
Effect: opening the search popup searches with the engine named by search.default; after a reader switches engines in the dropdown, the next open keeps their choice.
Corresponding config:
search:
default: "local"2.2 Common options
① Change the default engine
Effect: the popup’s preferred search backend changes, and result ordering and matching change with it.
Corresponding config:
search:
default: "pagefind"② Persist the reader’s choice
Effect: after switching engines the choice is written to localStorage, so it need not be picked again.
Corresponding config: none — the frontend handles it automatically.
2.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
search.default | string | "algolia" | local / algolia / pagefind | Default engine |
- Resolution order:
localStorage['search_engine']memory →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 the choice is written tolocalStorage.
2.4 Boundaries & conflicts
localStoragehas the highest priority — after changingsearch.default, returning readers still use the engine they picked last (expected behavior).- If every engine is disabled the popup shows no results, with no fallback message.
2.5 Summary
- Minimal setup:
default+enable: trueon the matching engine - Changed the default but nothing happened: clear
localStorage['search_engine']first - Degradation warning: means the default engine is not enabled
3. Local Search search.local
Purpose: search in the browser using a theme-generated JSON index, with no external service.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
3.1 How to enable
Effect: the build produces /search.json; opening the popup and typing shows results (trigger: auto) with hits highlighted; the first search downloads the index.
Corresponding config:
search:
local:
enable: true
path: /search.json
field: [post, wiki]
content: true
trigger: auto3.2 Common options
① Search titles only (smaller index)
Effect: the index shrinks noticeably and loads faster, but body keywords are no longer findable.
Corresponding config:
search:
local:
content: false② Widen the search scope
Effect: pages (page) and wiki (wiki) also enter the results, not just posts.
Corresponding config:
search:
local:
field: all③ Change the trigger mode
Effect: with manual, typing does not search; you must press Enter or click the button.
Corresponding config:
search:
local:
trigger: manual④ Snippets per article
Effect: 1 shows one hit snippet per post, -1 shows all of them.
Corresponding config:
search:
local:
top_n_per_article: -13.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
search.local.enable | bool | true | true / false | Master switch |
search.local.path | string | /search.json | output path | Index file location |
search.local.field | string / array | [post, wiki] | post / page / wiki / all / array combination | Search scope |
search.local.content | bool | true | true / false | Whether to index body text (false = titles only) |
search.local.format | string | striptags | striptags / raw | Body text format in the index |
search.local.trigger | string | auto | auto / manual | Trigger mode |
search.local.top_n_per_article | number | 1 | positive integer / -1 (all) | Hit snippets per article |
search.local.unescape | bool | false | true / false | Unescape HTML entities (reserved, not wired up) |
search.local.preload | bool | false | true / false | Prefetch the index on page load (reserved, not wired up) |
3.4 Boundaries & conflicts
unescape/preloadare reserved options, not wired up in the current implementation; changing them has no effect.format: rawkeeps HTML, making the index noticeably larger.- With
content: false, body keywords cannot be found — only titles match.
3.5 Summary
- Minimal setup:
enable: true(keep the rest at defaults) - Index too large:
content: falseor narrowfield - Want instant open: wait for
preloadto be wired up, or switch to Pagefind - Don’t fiddle with reserved options:
unescape/preloadcurrently do nothing
4. Algolia search.algolia
Purpose: remote index search with better relevance ranking and fault tolerance; requires a push at build time.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
4.1 How to enable
Effect: search goes through the Algolia service, and results carry excerpts and timing stats; the index is pushed at build time, so new posts are unfindable until pushed.
Corresponding config:
search:
algolia:
enable: true
applicationID: "your App ID"
apiKey: "your Search-Only API Key"
indexName: "blog"4.2 Common options
① Control the indexed body length
Effect: the larger content_length, the wider the searchable body range, but the larger each record — records over 10KB are rejected by Algolia.
Corresponding config:
search:
algolia:
content_length: 2500② Control excerpt length
Effect: the length of the excerpt snippet in results changes.
Corresponding config:
search:
algolia:
excerpt_length: 300③ Results per page and batch size
Effect: the number of results per page and the push batch size at build time change.
Corresponding config:
search:
algolia:
batch_size: 1000
hits:
per_page: 10④ UI copy
Effect: the search input placeholder, the no-results message and the result-stats copy change.
Corresponding config:
search:
algolia:
labels:
input_placeholder: "Search for Posts"
hits_empty: "We didn't find any results for the search: ${query}"
hits_stats: "${hits} results found in ${time} ms"4.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
search.algolia.enable | bool | true | true / false | Master switch |
search.algolia.applicationID | string | — | Algolia App ID | Application identifier |
search.algolia.apiKey | string | — | Search-Only API Key | Frontend search credential (safe to expose) |
search.algolia.indexName | string | — | index name | Target index |
search.algolia.content_length | number | 2500 | positive integer (chars); 2000–2500 recommended for CJK | Body truncation length |
search.algolia.excerpt_length | number | 300 | positive integer (chars); 150–300 recommended | Excerpt truncation length |
search.algolia.batch_size | number | 1000 | positive integer (whole batch ≤ 10MB) | Push batch size |
search.algolia.hits.per_page | number | 10 | positive integer | Results per page |
search.algolia.labels.input_placeholder | string | — | any string | Input placeholder |
search.algolia.labels.hits_empty | string | — | string containing ${query} | No-results message |
search.algolia.labels.hits_stats | string | — | contains ${hits}/${time} | Result stats copy |
deploy.algolia_write_key | string | — | Write API Key | Build-time push credential (never injected into the frontend) |
content_length: number of body plain-text characters to keep;excerpt_length: number of excerpt characters to keep.batch_size: push batch size;hits.per_page: results per page.labels.*:input_placeholder/hits_empty/hits_stats.- The write credential is separated from the frontend: build-time pushes use
deploy.algolia_write_key, which is never injected into the frontend.
4.4 Boundaries & conflicts
- Algolia has a hard per-record limit of 10KB (10240 bytes); anything larger is rejected on push (HTTP 400). UTF-8 CJK takes 3 bytes per character, and after subtracting the overhead of title/tags fields (about 500B): roughly 3000 CJK characters, or about 9000 ASCII characters.
content_length: 25000is guaranteed to fail. apiKeyis the frontend search credential and is safe to expose;deploy.algolia_write_keyis the write credential and must stay on the build side only.- If you change content without rebuilding and pushing, search results still come from the old index.
4.5 Summary
- Minimal setup:
enable+applicationID+apiKey+indexName - Push returns 400:
content_lengthis too large — cut it to the 10KB limit - New posts unfindable: the index was not pushed
- Never put the write credential into
apiKey
5. Pagefind search.pagefind
Purpose: a purely static index generated by scanning
public/after the build, searched in the browser with no server and no external network.Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
5.1 How to enable
Effect: index files appear under public/pagefind/, and searching happens entirely in the frontend; encrypted posts do not appear in results.
Corresponding config:
search:
pagefind:
enable: true
output_subdir: pagefindBuild step: after hexo generate and before deploy, run npx pagefind --site public --output-subdir pagefind.
5.2 Common options
① Change the index subdirectory
Effect: the index is output to public/<name>/, and the search request path changes accordingly.
Corresponding config:
search:
pagefind:
output_subdir: myindex5.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
search.pagefind.enable | bool | true | true / false | Master switch |
search.pagefind.output_subdir | string | pagefind | subdirectory name relative to public/ | Index output location |
output_subdir: index subdirectory (relative topublic/), defaultpagefind.- Build step: after
hexo generateand before deploy, runnpx pagefind --site public --output-subdir pagefind. - Encrypted posts are excluded automatically via conditional
data-pagefind-bodyrendering.
5.4 Boundaries & conflicts
- Avoid directory names starting with an underscore: GitHub Pages (Jekyll) ignores directories/files starting with
_. - Running only
hexo generatewithout pagefind leaves this engine with no index and no results. - The index is a build artifact; post updates require re-scanning.
5.5 Summary
- Minimal setup:
enable: true+ run pagefind once after the build - Nothing found: confirm
public/pagefind/exists - Directory name: don’t start it with
_ - Encrypted posts: excluded automatically, no config needed
6. Multi-language & Highlighting
Purpose: result grouping and language preference on multi-language sites, plus the highlighting implementation shared by all three engines.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
6.1 How to enable
Effect: search results show the current language version first and other languages after it; hits are wrapped in <mark>.
Corresponding config: no separate switch — it works automatically with the preference language block and the search config.
6.2 Common options
① Language preference
Effect: results are ordered by the language the reader chose last.
Corresponding config:
preference:
default_lang: zh-cnThe reader preference is stored in localStorage['wiki_lang']; invalid values fall back to the default language.
6.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
preference.default_lang | string | zh-cn | an enabled language | Fallback language when the preference is invalid |
search.local.field | string / array | [post, wiki] | see §3 | Decides which language versions enter the index |
- Result filtering:
applyLangFilter→groupAndFilterinsearch.js, grouping by the path’s language prefix. - Language preference: read from
localStorage['wiki_lang']; invalid values fall 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).
6.4 Boundaries & conflicts
- Language grouping is decided by the path prefix; a translated page missing
langis grouped under the default language. - Highlighting always goes through the shared
SearchEngine._highlight; changing a single engine’s highlight styles has no effect.
6.5 Summary
- Defaults are correct: no extra configuration needed
- Results in a jumbled language order: check
preference.default_langand the translated pages’lang - Highlight styles: change the shared
_highlight, not a single engine