@easyops-cn/docusaurus-search-local 0.49.2 → 0.50.0

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,14 @@
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.50.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.49.2...v0.50.0) (2025-06-03)
6
+
7
+
8
+ ### Features
9
+
10
+ * support setting a language list to remove their default stop word filter ([3b5fe70](https://github.com/easyops-cn/docusaurus-search-local/commit/3b5fe7066e8138d6317bc3f3325ec0d84a9c21ce))
11
+ * support setting a language list to remove their default stop word filter ([e7ce7ac](https://github.com/easyops-cn/docusaurus-search-local/commit/e7ce7ac88484b0e738562a79e9d9f2a81ed6e162)), closes [#517](https://github.com/easyops-cn/docusaurus-search-local/issues/517)
12
+
5
13
  ## [0.49.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.49.1...v0.49.2) (2025-03-31)
6
14
 
7
15
 
@@ -1,5 +1,5 @@
1
1
  export let language = ["en", "zh"];
2
- export let removeDefaultStopWordFilter = false;
2
+ export let removeDefaultStopWordFilter = [];
3
3
  export const searchIndexUrl = "search-index{dir}.json?_=abc";
4
4
  export const searchResultLimits = 8;
5
5
  export let fuzzyMatchingDistance = 0;
@@ -35,13 +35,14 @@ export function smartQueries(tokens, zhDictionary) {
35
35
  const stopWordPipelines = [];
36
36
  for (const lang of language) {
37
37
  if (lang === "en") {
38
- if (!removeDefaultStopWordFilter) {
38
+ if (!removeDefaultStopWordFilter.includes(lang)) {
39
39
  stopWordPipelines.unshift(lunr.stopWordFilter);
40
40
  }
41
41
  }
42
42
  else {
43
43
  const lunrLang = lunr[lang];
44
- if (lunrLang.stopWordFilter) {
44
+ if (lunrLang.stopWordFilter &&
45
+ !removeDefaultStopWordFilter.includes(lang)) {
45
46
  stopWordPipelines.unshift(lunrLang.stopWordFilter);
46
47
  }
47
48
  }
@@ -40,13 +40,24 @@ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, remov
40
40
  .map((documents) => ({
41
41
  documents,
42
42
  index: (0, lunr_1.default)(function () {
43
+ var _a;
43
44
  if (plugin) {
44
45
  this.use(plugin);
45
46
  }
46
- if (removeDefaultStopWordFilter) {
47
- // Sometimes we need no English stop words,
48
- // since they are almost all programming code.
49
- this.pipeline.remove(lunr_1.default.stopWordFilter);
47
+ // Sometimes we need no English stop words,
48
+ // since they are almost all programming code.
49
+ for (const lang of language) {
50
+ if (removeDefaultStopWordFilter.includes(lang)) {
51
+ if (lang === "en") {
52
+ this.pipeline.remove(lunr_1.default.stopWordFilter);
53
+ }
54
+ else {
55
+ const stopWordFilter = (_a = lunr_1.default[lang]) === null || _a === void 0 ? void 0 : _a.stopWordFilter;
56
+ if (stopWordFilter) {
57
+ this.pipeline.remove(stopWordFilter);
58
+ }
59
+ }
60
+ }
50
61
  }
51
62
  if (removeDefaultStemmer) {
52
63
  this.pipeline.remove(lunr_1.default.stemmer);
@@ -22,6 +22,11 @@ function processPluginOptions(options, { siteDir, siteConfig: { themeConfig }, }
22
22
  config.searchBarPosition =
23
23
  search && search.position === "left" ? "left" : "right";
24
24
  }
25
+ if (!Array.isArray(config.removeDefaultStopWordFilter)) {
26
+ config.removeDefaultStopWordFilter = config.removeDefaultStopWordFilter
27
+ ? ["en"]
28
+ : [];
29
+ }
25
30
  return config;
26
31
  }
27
32
  exports.processPluginOptions = processPluginOptions;
@@ -15,7 +15,9 @@ const schema = utils_validation_1.Joi.object({
15
15
  hashed: isBooleanOrString.default(false),
16
16
  docsDir: isStringOrArrayOfStrings.default(["docs"]),
17
17
  blogDir: isStringOrArrayOfStrings.default(["blog"]),
18
- removeDefaultStopWordFilter: utils_validation_1.Joi.boolean().default(false),
18
+ removeDefaultStopWordFilter: utils_validation_1.Joi.alternatives()
19
+ .try(utils_validation_1.Joi.boolean(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()))
20
+ .default([]),
19
21
  removeDefaultStemmer: utils_validation_1.Joi.boolean().default(false),
20
22
  highlightSearchTermsOnTargetPage: utils_validation_1.Joi.boolean().default(false),
21
23
  searchResultLimits: utils_validation_1.Joi.number().default(8),
@@ -64,8 +64,10 @@ export interface PluginOptions {
64
64
  /**
65
65
  * Sometimes people (E.g., us) want to keep the English stop words as indexed, since they
66
66
  * maybe are relevant in programming docs.
67
+ *
68
+ * Set a language list to remove their default stop word filter, `true` is equivalent to `["en"]`.
67
69
  */
68
- removeDefaultStopWordFilter?: boolean;
70
+ removeDefaultStopWordFilter?: boolean | string[];
69
71
  /**
70
72
  * Enable this if you want to be able to search for any partial word at the cost of search performance.
71
73
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.49.2",
3
+ "version": "0.50.0",
4
4
  "description": "An offline/local search plugin for Docusaurus v3",
5
5
  "repository": {
6
6
  "type": "git",