Loading...

Loading...

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 search block in userConfig/_config.tmp.yml, injected into the theme config at build time.

1. Engine Overview

EngineConfig keyIndex
Localsearch.local/search.json (generated by theme generator)
Algoliasearch.algoliaremote index (pushed at build time)
Pagefindsearch.pagefindpublic/pagefind/ (scanned after build)

2. Default Engine & Switching

  • search.default: one of local / 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, items data-engine=local|algolia|pagefind); switching destroys the old engine and inits the new one, and persists to localStorage.

3. Local Search search.local

KeyDescription
enableMaster switch
pathIndex output path, default /search.json
fieldScope: post / page / wiki / all, or an array
contentIndex body text (false = titles only)
formatstriptags (strip HTML) or raw
triggerauto (search as you type) or manual (Enter/button)
top_n_per_articleMax hit snippets per article, -1 = all
unescape / preloadReserved; 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_key is build-only and never injected.

5. Pagefind search.pagefind

  • enable: master switch.
  • output_subdir: index subdirectory (relative to public/), default pagefind.
  • Build step: after hexo generate, before deploy, run npx pagefind --site public --output-subdir pagefind.
  • Encrypted posts are excluded automatically via conditional data-pagefind-body rendering.

6. Multi-language & Highlighting

  • Filtering: applyLangFilter → groupAndFilter in search.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).
Comments
Data Loading...