Skip to content

Configuration

The Starlight Docsearch Typesense plugin is configured in your project’s astro.config.mjs file:

import starlight from '@astrojs/starlight';
import { defineConfig } from 'astro/config';
import starlightDocSearchTypesense from 'starlight-docsearch-typesense';
export default defineConfig({
integrations: [
starlight({
plugins: [
starlightDocSearchTypesense({
// Configuration options go here.
}),
],
title: 'My Docs',
}),
],
});

You can pass the following options to starlightDocSearchTypesense():

PropertyType                    Description
typesenseCollectionName RequiredstringThe name of the Typesense collection to search. If using typesense-docsearch-scraper, it must match the index_name field in the scraper config file.
typesenseServerConfig RequiredobjectConfiguration object for connecting to the Typesense server. See Typesense Server Config below.
typesenseSearchParametersSearchOptionsAdditional Typesense search parameters to fine-tune search behavior (e.g., filters, facets, ranking).
disableUserPersonalization default: falsebooleanDisables storing recent searches and favorites in local storage.
initialQuerystringInitial query string to prefill the search box when the component first renders.
PropertyTypeDescription
apiKey RequiredstringThe API key used to authenticate with the Typesense server.
nodes RequiredArray<Node>List of Typesense nodes.
randomizeNodesbooleanRandomizes the order of nodes for load balancing.
nearestNodeNodeThe node prioritized for making requests, usually the load-balanced endpoint.
connectionTimeoutSecondsnumberConnection timeout for API calls, in seconds.
healthcheckIntervalSecondsnumberFrequency to perform health checks for failed nodes.
numRetriesnumberNumber of retry attempts for failed requests.
retryIntervalSecondsnumberDelay between retry attempts, in seconds.
sendApiKeyAsQueryParambooleanSends the API key as a query parameter instead of a header.
useServerSideSearchCachebooleanEnables the server-side search cache feature.
cacheSearchResultsForSecondsnumberDuration to cache search results.
additionalHeadersRecord<string, string>Custom HTTP headers to send with every request.
logLevel'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent'Sets the verbosity level for client logs.

You can extend the plugin with custom DocSearch client behavior in a separate configuration file, similar to the official @astrojs/starlight-docsearch plugin.

  1. Create a TypeScript file exporting your DocSearch configuration.

    src/config/docsearch.ts
    import type { DocSearchClientOptions } from 'starlight-docsearch-typesense';
    export default {
    typesenseCollectionName: 'YOUR_COLLECTION_NAME',
    typesenseServerConfig: {
    nodes: [{ url: 'https://typesense-1.example.net:443' }],
    apiKey: 'YOUR_SEARCH_API_KEY',
    },
    getMissingResultsUrl({ query }) {
    return `https://github.com/typesense/typesense-docsearch.js/issues/new?title=${query}`;
    },
    // ...
    } satisfies DocSearchClientOptions;
  2. Pass the path to your configuration file to the Starlight DocSearch plugin through clientOptionsModule.

    astro.config.mjs
    import { defineConfig } from 'astro/config';
    import starlight from '@astrojs/starlight';
    import starlightDocSearchTypesense from 'starlight-docsearch-typesense';
    export default defineConfig({
    integrations: [
    starlight({
    title: 'Site with DocSearch',
    plugins: [
    starlightDocSearchTypesense({
    clientOptionsModule: './src/config/docsearch.ts',
    }),
    ],
    }),
    ],
    });