diff --git a/docs/plugins/flexsearch.md b/docs/plugins/flexsearch.md index bc9bcbc259..3bf0831b91 100644 --- a/docs/plugins/flexsearch.md +++ b/docs/plugins/flexsearch.md @@ -124,31 +124,6 @@ export default { } ``` -### getExtraFields - -- Type: `(page: Page) => string[]` - -- Default: `() => []` - -- Details: - - A function to add extra fields to the search index of a page. - - By default, this plugin will use page title and headers as the search index. This option could help you to add more searchable fields. - -- Example: - -```ts -export default { - plugins: [ - searchPlugin({ - // allow searching the `tags` frontmatter - getExtraFields: (page) => page.frontmatter.tags ?? [], - }), - ], -} -``` - ## Styles You can customize the style of the search box via CSS variables: diff --git a/plugins/plugin-flexsearch/src/node/flexsearchPlugin.ts b/plugins/plugin-flexsearch/src/node/flexsearchPlugin.ts index 455a8b03ea..760b328cad 100644 --- a/plugins/plugin-flexsearch/src/node/flexsearchPlugin.ts +++ b/plugins/plugin-flexsearch/src/node/flexsearchPlugin.ts @@ -40,11 +40,6 @@ export interface SearchPluginOptions { * A function to determine whether a page should be included in the search index */ isSearchable?: (page: Page) => boolean - - /** - * A function to add extra fields to the search index of a page - */ - getExtraFields?: (page: Page) => string[] } export const flexsearchPlugin = ({ @@ -52,7 +47,6 @@ export const flexsearchPlugin = ({ hotKeys = ['s', '/'], maxSuggestions = 5, isSearchable = () => true, - getExtraFields = () => [], }: SearchPluginOptions = {}): Plugin => ({ name: '@vuepress/plugin-flexsearch', @@ -65,25 +59,23 @@ export const flexsearchPlugin = ({ }, onPrepared: async (app) => { - await prepareSearchIndex({ app, isSearchable, getExtraFields }) + await prepareSearchIndex({ app, isSearchable }) }, onWatched: (app, watchers) => { // here we only watch the page data files - // if the extra fields generated by `getExtraFields` are not included - // in the page data, the changes may not be watched const searchIndexWatcher = chokidar.watch('pages/**/*.js', { cwd: app.dir.temp(), ignoreInitial: true, }) searchIndexWatcher.on('add', () => { - prepareSearchIndex({ app, isSearchable, getExtraFields }) + prepareSearchIndex({ app, isSearchable }) }) searchIndexWatcher.on('change', () => { - prepareSearchIndex({ app, isSearchable, getExtraFields }) + prepareSearchIndex({ app, isSearchable }) }) searchIndexWatcher.on('unlink', () => { - prepareSearchIndex({ app, isSearchable, getExtraFields }) + prepareSearchIndex({ app, isSearchable }) }) watchers.push(searchIndexWatcher) }, diff --git a/plugins/plugin-flexsearch/src/node/prepareSearchIndex.ts b/plugins/plugin-flexsearch/src/node/prepareSearchIndex.ts index cd1e194aae..b487e03b90 100644 --- a/plugins/plugin-flexsearch/src/node/prepareSearchIndex.ts +++ b/plugins/plugin-flexsearch/src/node/prepareSearchIndex.ts @@ -31,11 +31,9 @@ const prepContent = (html: string): string => { export const prepareSearchIndex = async ({ app, isSearchable, - getExtraFields, }: { app: App isSearchable: Required['isSearchable'] - getExtraFields: Required['getExtraFields'] }): Promise => { // generate search index const pages = app.pages.filter(isSearchable)