Skip to main content

Config

About 3 min

Plugin Options

indexContent

  • Type: boolean
  • Default: false

Whether to enable content indexing.

Tips

By default, only headings and excerpt of the page will be indexed along with your custom fields, and the content of the page will not be indexed. If you need to index the content of the page, you can set this option to true

customFields

  • Type: SearchProCustomFieldOptions[]

    interface SearchProCustomFieldOptions {
      /**
       * Custom field getter
       */
      getter: (page: Page) => string | string[] | null;
    
      /**
       * Display content
       *
       * @description `$content` will be replaced by the content returned by `getter`
       *
       * @default `$content`
       */
      formatter?: string | Record<string, string>;
    }
    
  • Required: No

Custom search items.

Example

Assuming your theme uses category and tag tags in Frontmatter to mark categories and tags of articles, you can use the following configuration:

import { defineUserConfig } from "vuepress";
import { searchProPlugin } from "vuepress-plugin-search-pro";

export default defineUserConfig({
  // We assume you are using the following multilingual
  locales: {
    "/": {
      lang: "en-US",
    },
    "/zh/": {
      lang: "zh-CN",
    },
  },

  plugins: [
    searchProPlugin({
      customFields: [
        {
          getter: (page) => page.frontmatter.category,
          formatter: {
            "/": "Category: $content",
            "/zh/": "分类:$content",
          },
        },
        {
          getter: (page) => page.frontmatter.tag,
          formatter: {
            "/": "Tag: $content",
            "/zh/": "标签:$content",
          },
        },
      ],
    }),
  ],
});

hotKeys

  • Type: SearchProHotKeyOptions[]

    interface SearchProHotKeyOptions {
      /**
       * Value of `event.key` to trigger the hot key
       */
      key: string;
    
      /**
       * Whether to press `event.altKey` at the same time
       *
       * @default false
       */
      alt?: boolean;
    
      /**
       * Whether to press `event.ctrlKey` at the same time
       *
       * @default false
       */
      ctrl?: boolean;
    
      /**
       * Whether to press `event.shiftKey` at the same time
       *
       * @default false
       */
      shift?: boolean;
    
      /**
       * Whether to press `event.metaKey` at the same time
       *
       * @default false
       */
      meta?: boolean;
    }
    
  • Default: [{ key: "k", ctrl: true }, { key: "/", ctrl: true }]

Specify the event.keyopen in new window of the hotkeys.

When hotkeys are pressed, the search box input will be focused. Set to an empty array to disable hotkeys.

queryHistoryCount

  • Type: number
  • Default: 5

Max stored query history count, set 0 to disable it.

resultHistoryCount

  • Type: number
  • Default: 5

Max stored matched result history count, set 0 to disable it.

delay

  • Type: number
  • Default: 150

Delay to start searching after input.

Note

Performing client search with huge contents could be slow, so under this case you might need to increase this value to ensure user finish input before searching.

worker

  • Type: string
  • Default: search-pro.worker.js

Output Worker filename

hotReload

  • Type: boolean
  • Default: Whether using --debug flag

Whether to enable hot reload in the development server.

Note

It is disabled by default because this feature can have a huge performance impact on sites with huge content and drastically increases the speed of hot reloads when editing Markdown.

Usually in development, users do not need to update the index database in real time.

indexOptions

  • Type: SearchProIndexOptions

    export interface SearchProIndexOptions {
      /**
       * Function to tokenize the index field item.
       */
      tokenize?: (text: string, fieldName?: string) => string[];
      /**
       * Function to process or normalize terms in the index field.
       */
      processTerm?: (
        term: string
      ) => string | string[] | null | undefined | false;
    }
    
  • Required: No

Options used to create index.

indexLocaleOptions

  • Type: Record<string, SearchProIndexOptions>

    export interface SearchProIndexOptions {
      /**
       * Function to tokenize the index field item.
       */
      tokenize?: (text: string, fieldName?: string) => string[];
      /**
       * Function to process or normalize terms in the index field.
       */
      processTerm?: (
        term: string
      ) => string | string[] | null | undefined | false;
    }
    
  • Required: No

Options used to create index per locale.

locales

  • Type: SearchProLocaleConfig

    /**
     * Multi language config for `vuepress-plugin-search-pro` plugin
     */
    interface SearchProLocaleData {
      /**
       * Search box placeholder text
       */
      placeholder: string;
    
      /**
       * Search text
       */
      search: string;
    
      /**
       * Close text
       */
      close: string;
    
      /**
       * Select hint
       */
      select: string;
    
      /**
       * Choose hint
       */
      navigate: string;
    
      /**
       * Close hint
       */
      exit: string;
    
      /**
       * Loading hint
       */
      loading: string;
    
      /**
       * Empty hint
       */
      empty: string;
    }
    
    interface SearchProLocaleConfig {
      [localePath: string]: SearchProLocaleData;
    }
    
  • Required: No

Multilingual configuration of the search plugin.

Built-in Supported Languages
  • Simplified Chinese (zh-CN)
  • Traditional Chinese (zh-TW)
  • English (United States) (en-US)
  • German (de-DE)
  • German (Australia) (de-AT)
  • Russian (ru-RU)
  • Ukrainian (uk-UA)
  • Vietnamese (vi-VN)
  • Portuguese (Brazil) (pt-BR)
  • Polish (pl-PL)
  • French (fr-FR)
  • Spanish (es-ES)
  • Slovak (sk-SK)
  • Japanese (ja-JP)
  • Turkish (tr-TR)
  • Korean (ko-KR)
  • Finnish (fi-FI)
  • Indonesian (id-ID)
  • Dutch (nl-NL)

Client Config

defineSearchConfig

Customize search optionsopen in new window.

// .vuepress/client.ts
import { defineSearchConfig } from "vuepress-plugin-search-pro/client";

defineSearchConfig({
  // search options here
});

export default {};

createSearchWorker

Create a search worker so that you can search through API.

export type Word = [tag: string, content: string] | string;

export interface TitleMatchedItem {
  type: "title";
  id: string;
  display: Word[];
}

export interface HeadingMatchedItem {
  type: "heading";
  id: string;
  display: Word[];
}

export interface CustomMatchedItem {
  type: "custom";
  id: string;
  index: string;
  display: Word[];
}

export interface ContentMatchedItem {
  type: "content";
  id: string;
  header: string;
  display: Word[];
}

export type MatchedItem =
  | TitleMatchedItem
  | HeadingMatchedItem
  | ContentMatchedItem
  | CustomMatchedItem;

export interface SearchResult {
  title: string;
  contents: MatchedItem[];
}

export interface SearchWorker {
  search: (
    query: string,
    locale: string,
    searchOptions?: SearchOptions
  ) => Promise<SearchResult[]>;
  terminate: () => void;
}

declare const createSearchWorker: (
  options: SearchWorkerOptions
) => SearchWorker;