Search

Sveltepress default theme supports three ways to add search to your site:

  • Algolia DocSearch — via the built-in docsearch option
  • Meilisearch — via @sveltepress/meilisearch and the search option
  • Custom search — pass any Svelte component or a module path string to the search option

Algolia DocSearch

Pass a docsearch config object to defaultTheme to enable Algolia DocSearch in the navbar.

Required fields are appId, apiKey, and indexName. Every other DocSearch option is also accepted.

vite.config.(js|ts)
import {  } from '@sveltepress/theme-default'
import {  } from '@sveltepress/vite'
import {  } from 'vite'

export default ({
  : [
    ({
      : ({
        : {
          : 'YOUR_APP_ID',
          : 'YOUR_SEARCH_API_KEY',
          : 'YOUR_INDEX_NAME',
        },
      }),
    }),
  ],
})
ts
Apply for DocSearch

DocSearch is free for open-source documentation sites. Apply at docsearch.algolia.com .

Meilisearch

Meilisearch is an open-source, self-hosted search engine. Use the @sveltepress/meilisearch package together with the search option to add it to your site.

Installation

npm install --save @sveltepress/meilisearch
sh

Configuration

Pass the path to the Search.svelte component exported by @sveltepress/meilisearch to the search option:

vite.config.(js|ts)
import {  } from '@sveltepress/theme-default'
import {  } from '@sveltepress/vite'
import {  } from 'vite'

export default ({
  : [
    ({
      : ({
        : '@sveltepress/meilisearch/Search.svelte',
      }),
    }),
  ],
})
ts

The Search.svelte component accepts the following props. You can pass them by creating a thin wrapper component around the imported Search.svelte and providing them as props.

PropTypeRequiredDescription
hoststringURL of your Meilisearch instance
apiKeystringSearch-only API key
indexNamestringIndex name to search
placeholderstringPlaceholder text for the search input (default: 'Search...')
limitnumberMaximum number of results to show (default: 10)
Self-hosted vs Meilisearch Cloud

You can host Meilisearch yourself or use Meilisearch Cloud . The host URL points to whichever deployment you choose.

Custom Search

The search option also accepts a Svelte Component directly, which lets you use any search library you like:

vite.config.(js|ts)
import {  } from '@sveltepress/theme-default'
import {  } from '@sveltepress/vite'
import {  } from 'vite'
import  from './src/components/MySearchComponent.svelte'

export default ({
  : [
    ({
      : ({
        : ,
      }),
    }),
  ],
})
ts
search vs docsearch priority

When both search and docsearch are provided, search takes priority and docsearch is ignored.

Last update at: 2026/03/09 12:36:50