mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-22 22:03:35 -04:00
Removed deprecated prebuilt index support
This commit is contained in:
@@ -68,7 +68,6 @@ export interface SearchIndexDocument {
|
||||
export interface SearchIndex {
|
||||
config: SearchIndexConfig /* Search index configuration */
|
||||
docs: SearchIndexDocument[] /* Search index documents */
|
||||
index?: object /* Prebuilt index */
|
||||
options: SearchOptions /* Search options */
|
||||
}
|
||||
|
||||
@@ -162,7 +161,7 @@ export class Search {
|
||||
*
|
||||
* @param data - Search index
|
||||
*/
|
||||
public constructor({ config, docs, index, options }: SearchIndex) {
|
||||
public constructor({ config, docs, options }: SearchIndex) {
|
||||
this.options = options
|
||||
|
||||
/* Set up document map and highlighter factory */
|
||||
@@ -172,48 +171,42 @@ export class Search {
|
||||
/* Set separator for tokenizer */
|
||||
lunr.tokenizer.separator = new RegExp(config.separator)
|
||||
|
||||
/* If no index was given, create it */
|
||||
if (typeof index === "undefined") {
|
||||
this.index = lunr(function () {
|
||||
/* Create search index */
|
||||
this.index = lunr(function () {
|
||||
|
||||
/* Set up multi-language support */
|
||||
if (config.lang.length === 1 && config.lang[0] !== "en") {
|
||||
this.use((lunr as any)[config.lang[0]])
|
||||
} else if (config.lang.length > 1) {
|
||||
this.use((lunr as any).multiLanguage(...config.lang))
|
||||
/* Set up multi-language support */
|
||||
if (config.lang.length === 1 && config.lang[0] !== "en") {
|
||||
this.use((lunr as any)[config.lang[0]])
|
||||
} else if (config.lang.length > 1) {
|
||||
this.use((lunr as any).multiLanguage(...config.lang))
|
||||
}
|
||||
|
||||
/* Compute functions to be removed from the pipeline */
|
||||
const fns = difference([
|
||||
"trimmer", "stopWordFilter", "stemmer"
|
||||
], options.pipeline)
|
||||
|
||||
/* Remove functions from the pipeline for registered languages */
|
||||
for (const lang of config.lang.map(language => (
|
||||
language === "en" ? lunr : (lunr as any)[language]
|
||||
))) {
|
||||
for (const fn of fns) {
|
||||
this.pipeline.remove(lang[fn])
|
||||
this.searchPipeline.remove(lang[fn])
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute functions to be removed from the pipeline */
|
||||
const fns = difference([
|
||||
"trimmer", "stopWordFilter", "stemmer"
|
||||
], options.pipeline)
|
||||
/* Set up reference */
|
||||
this.ref("location")
|
||||
|
||||
/* Remove functions from the pipeline for registered languages */
|
||||
for (const lang of config.lang.map(language => (
|
||||
language === "en" ? lunr : (lunr as any)[language]
|
||||
))) {
|
||||
for (const fn of fns) {
|
||||
this.pipeline.remove(lang[fn])
|
||||
this.searchPipeline.remove(lang[fn])
|
||||
}
|
||||
}
|
||||
/* Set up fields */
|
||||
this.field("title", { boost: 1e3 })
|
||||
this.field("text")
|
||||
|
||||
/* Set up reference */
|
||||
this.ref("location")
|
||||
|
||||
/* Set up fields */
|
||||
this.field("title", { boost: 1e3 })
|
||||
this.field("text")
|
||||
|
||||
/* Index documents */
|
||||
for (const doc of docs)
|
||||
this.add(doc)
|
||||
})
|
||||
|
||||
/* Handle prebuilt index */
|
||||
} else {
|
||||
this.index = lunr.Index.load(index)
|
||||
}
|
||||
/* Index documents */
|
||||
for (const doc of docs)
|
||||
this.add(doc)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,9 +58,7 @@ export type SearchWorker = WorkerHandler<SearchMessage>
|
||||
*
|
||||
* @returns Search index
|
||||
*/
|
||||
function setupSearchIndex(
|
||||
{ config, docs, index }: SearchIndex
|
||||
): SearchIndex {
|
||||
function setupSearchIndex({ config, docs }: SearchIndex): SearchIndex {
|
||||
|
||||
/* Override default language with value from translation */
|
||||
if (config.lang.length === 1 && config.lang[0] === "en")
|
||||
@@ -84,7 +82,7 @@ function setupSearchIndex(
|
||||
}
|
||||
|
||||
/* Return search index after defaulting */
|
||||
return { config, docs, index, options }
|
||||
return { config, docs, options }
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user