From be4957a05dfc36f870e608f119a878f911a4d48c Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 17 Jul 2022 12:32:24 +0200 Subject: Set up the pipeline for indexing content in multiple languages --- assets/js/search.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'assets/js') diff --git a/assets/js/search.js b/assets/js/search.js index e964358..6cca4a5 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -12,13 +12,26 @@ async function initSearchIndex() { // Create the lunr index for the search searchIndex = lunr(function () { // eslint-disable-line no-undef - this.use(lunr.multiLanguage('de', 'en', 'es', 'fr', 'it', 'pt', 'ru')); // eslint-disable-line no-undef + // Set up the pipeline for indexing content in multiple languages + if (Array.isArray(searchConfig.lunrLanguages)) { + // Lunr has full support for the indexing and searching of + // documents in English. So no need add 'en'. + let langs = searchConfig.lunrLanguages.slice(); + langs = langs.filter(lang => lang !== 'en'); + + const pipeline = lunr.multiLanguage( // eslint-disable-line no-undef + ...langs + ); + + this.use(pipeline); + } this.field('objectID'); this.field('title'); this.field('categories'); this.field('tags'); this.field('content'); + this.ref('href'); pagesIndex.forEach((page) => this.add(page)); -- cgit v1.2.3