Search
Note
The search term will be stored in the reader’s browser as long as it is present.
Configure Search
The theme offers three levels of search through the menu’s search form:
- In-page search: Highlights search terms on the current page
- Search popup: Opens a popup with results from other pages
- Dedicated search page: Accessible by clicking the magnifier glass or pressing ENTER
Each level requires the previous one to be enabled. If no search is configured, the search form won’t appear.
Option All levels are enabled by default. Disable them in hugo.toml
:
- In-page search:
search.disable=true
- Search popup:
search.index.disable=true
- Dedicated search page:
search.page.disable=true
[params]
[params.search]
disable = true
[params.search.index]
disable = true
[params.search.page]
disable = true
params:
search:
disable: true
index:
disable: true
page:
disable: true
{
"params": {
"search": {
"disable": true,
"index": {
"disable": true
},
"page": {
"disable": true
}
}
}
}
Search URLs
Option Default URLs can be changed with the following parameter
- Search popup:
searchindex.js
set bysearch.index.URL
- Dedicated search page:
search/index.html
set bysearch.page.URL
[params]
[params.search]
[params.search.index]
URL = 'omnisearchindex.js'
[params.search.page]
URL = 'omnisearch'
params:
search:
index:
URL: omnisearchindex.js
page:
URL: omnisearch
{
"params": {
"search": {
"index": {
"URL": "omnisearchindex.js"
},
"page": {
"URL": "omnisearch"
}
}
}
}
Note
You only need to change these if you have own content created for those URLs. This can happen with uglyURLs=true
in hugo.toml
and having a content file at content/search.md
.
Check for duplicate URLs by running hugo --printPathWarnings
.
Search Adapter / Engine
Option The theme supports different search engines through adapters. Each different adapter may has its own set of configuration.
By default, it uses the Lunr search engine.
[params]
[params.search]
[params.search.adapter]
identifier = 'lunr'
params:
search:
adapter:
identifier: lunr
{
"params": {
"search": {
"adapter": {
"identifier": "lunr"
}
}
}
}
Lunr
lunr
is the default search adapter.
Supported Languages
Lunr doesn’t support all languages of the theme. Unsupported languages will show errors in the browser console. Currently unsupported are
- Czech
- Indonesian
- Persian
- Polish
- Swahili
- Ukrainian
Mixed Language Support
Option In case your page’s content contains text in multiple languages (for example, you are writing a Piratish documentation for your English API), you can set those languages in search.adapter.params.additionalContentLanguage
to broaden the search.
[params]
[params.search]
[params.search.adapter]
[params.search.adapter.params]
additionalContentLanguage = ['en']
params:
search:
adapter:
params:
additionalContentLanguage:
- en
{
"params": {
"search": {
"adapter": {
"params": {
"additionalContentLanguage": [
"en"
]
}
}
}
}
}
You can add multiple languages to this array.
Note
Use the base language code. For example, if your page is using zh-CN
, add zh
to this parameter.
Experimental Adapters
The theme also ships with the additional experimental orama
and orama-esm
(not usable for headless server deployments) adapters.
Customizing the Search Index Generation
Option You can customize how the search index is generated by specifying a different template:
[params]
[params.search]
[params.search.index]
template = '/custom_searchindex.js'
params:
search:
index:
template: /custom_searchindex.js
{
"params": {
"search": {
"index": {
"template": "/custom_searchindex.js"
}
}
}
}
By default, the theme uses /_relearn_searchindex.js
to generate the search index. When you specify a custom value for search.index.template
, the theme will look for the template file in your site’s assets
directory.
For example, if you set search.index.template = '/custom_searchindex.js'
, you would need to create a file at assets/custom_searchindex.js
in your site to define the custom index generation logic.
This advanced option is useful if you need to modify how content is indexed or change the structure of the search index to work with custom search implementations.
Customizing the Search Page Layout
Option You can customize the appearance of the dedicated search page by changing its content view:
[params]
[params.search]
[params.search.page]
type = 'custom_search_layout'
params:
search:
page:
type: custom_search_layout
{
"params": {
"search": {
"page": {
"type": "custom_search_layout"
}
}
}
}
By default, the theme uses _relearn_searchpage
as the search content view. When you specify a custom value for search.page.type=[YOUR-VIEWNAME]
, Hugo will look for a template file at layouts/[YOUR-VIEWNAME]/article.html
.
For example, if you set search.page.type = 'custom_search_layout'
, you would need to create a file at layouts/custom_search_layout/article.html
in your site to define the custom layout.
This allows you to maintain the search functionality while adapting its appearance to match your specific design requirements.
Migration from Relearn 7
In previous versions of the theme, search configuration used flat parameters. The current version uses a more structured approach with a search
namespace.
If you’re updating from an older version, here’s how to migrate your search configuration:
Migration Table
Legacy Parameter | New Parameter |
---|---|
disableSearch |
search.disable |
disableSearchIndex |
search.index.disable |
disableSearchPage |
search.page.disable |
searchIndexURL |
search.index.URL |
searchPageURL |
search.page.URL |
additionalContentLanguage |
search.adapter.params.additionalContentLanguage |