@easyops-cn/docusaurus-search-local 0.44.3 → 0.44.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [0.44.4](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.44.3...v0.44.4) (2024-07-19)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * do not initialize lunr multiple times, fixes [#155](https://github.com/easyops-cn/docusaurus-search-local/issues/155) ([0b323d9](https://github.com/easyops-cn/docusaurus-search-local/commit/0b323d97fbc238692e68368582bce72908fd66b0))
11
+
5
12
  ## [0.44.3](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.44.2...v0.44.3) (2024-07-08)
6
13
 
7
14
 
@@ -4,23 +4,34 @@ exports.buildIndex = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /* eslint @typescript-eslint/no-var-requires: 0 */
6
6
  const lunr_1 = tslib_1.__importDefault(require("lunr"));
7
+ let pluginInitialized = false;
8
+ let plugin;
7
9
  function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, zhUserDict, zhUserDictPath, }) {
8
- if (language.length > 1 || language.some((item) => item !== "en")) {
9
- require("lunr-languages/lunr.stemmer.support")(lunr_1.default);
10
- }
11
- if (language.includes("ja") || language.includes("jp")) {
12
- require("lunr-languages/tinyseg")(lunr_1.default);
13
- }
14
- for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
15
- require(`lunr-languages/lunr.${lang}`)(lunr_1.default);
16
- }
17
- if (language.includes("zh")) {
18
- const { tokenizer, loadUserDict } = require("./tokenizer");
19
- loadUserDict(zhUserDict, zhUserDictPath);
20
- require("../../shared/lunrLanguageZh").lunrLanguageZh(lunr_1.default, tokenizer);
21
- }
22
- if (language.length > 1) {
23
- require("lunr-languages/lunr.multi")(lunr_1.default);
10
+ if (!pluginInitialized) {
11
+ pluginInitialized = true;
12
+ if (language.length > 1 || language.some((item) => item !== "en")) {
13
+ require("lunr-languages/lunr.stemmer.support")(lunr_1.default);
14
+ }
15
+ if (language.includes("ja") || language.includes("jp")) {
16
+ require("lunr-languages/tinyseg")(lunr_1.default);
17
+ }
18
+ for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
19
+ require(`lunr-languages/lunr.${lang}`)(lunr_1.default);
20
+ }
21
+ if (language.includes("zh")) {
22
+ const { tokenizer, loadUserDict } = require("./tokenizer");
23
+ loadUserDict(zhUserDict, zhUserDictPath);
24
+ require("../../shared/lunrLanguageZh").lunrLanguageZh(lunr_1.default, tokenizer);
25
+ }
26
+ if (language.length > 1) {
27
+ require("lunr-languages/lunr.multi")(lunr_1.default);
28
+ }
29
+ if (language.length > 1) {
30
+ plugin = lunr_1.default.multiLanguage(...language);
31
+ }
32
+ else if (language[0] !== "en") {
33
+ plugin = lunr_1.default[language[0]];
34
+ }
24
35
  }
25
36
  // Some documents may be empty (unset array item), which is not mapped.
26
37
  return new Array(allDocuments.length)
@@ -29,11 +40,8 @@ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, remov
29
40
  .map((documents) => ({
30
41
  documents,
31
42
  index: (0, lunr_1.default)(function () {
32
- if (language.length > 1) {
33
- this.use(lunr_1.default.multiLanguage(...language));
34
- }
35
- else if (language[0] !== "en") {
36
- this.use(lunr_1.default[language[0]]);
43
+ if (plugin) {
44
+ this.use(plugin);
37
45
  }
38
46
  if (removeDefaultStopWordFilter) {
39
47
  // Sometimes we need no English stop words,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.44.3",
3
+ "version": "0.44.4",
4
4
  "description": "An offline/local search plugin for Docusaurus v3",
5
5
  "repository": {
6
6
  "type": "git",