easyops-cn / docusaurus-search-local

Offline/local search for Docusaurus v2/v3
https://easyops-cn.github.io/docusaurus-search-local/
MIT License
702 stars 89 forks source link

Warning `Overwriting existing registered function: lunr-multi-trimmer-en-zh` #155

Closed ApsarasX closed 2 months ago

ApsarasX commented 2 years ago

My Config is as shown below.

    [
      require.resolve('@easyops-cn/docusaurus-search-local'),
      {
        hashed: true,
        language: ['en', 'zh']
      }
    ]
image
brightzoe commented 2 years ago

Maybe you should update your config in docusaurus.config.js, move the config in plugins to themes. Please read the README, thx~

// In your docusaurus.config.js:

module.exports = {
  // ... Your other configurations.
  themes: [
    // ... Your other themes.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,
        // For Docs using Chinese, The `language` is recommended to set to:
        // ```
        // language: ["en", "zh"],
        // ```
      },
    ],
  ],
};
ApsarasX commented 2 years ago

Maybe you should update your config in docusaurus.config.js, move the config in plugins to themes. Please read the README, thx~

// In your docusaurus.config.js:

module.exports = {
  // ... Your other configurations.
  themes: [
    // ... Your other themes.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,
        // For Docs using Chinese, The `language` is recommended to set to:
        // ```
        // language: ["en", "zh"],
        // ```
      },
    ],
  ],
};

@brightzoe

The config of docusaurus-search-local is in the theme is indeed.😂

This is the docusaurus.config.js of my blog.

https://github.com/ApsarasX/blog/blob/619da4e1db998b182024a2ce90298eaf80ae9d0d/docusaurus.config.js#L60-L73

weareoutman commented 2 years ago

You can safely dismiss this warning.

o-l-a-v commented 2 months ago

The fix has been discussed in:

Seems this is fixed by:

Have you tried lifting the call to lunr.multiLanguage out of the regeneration function in order to call it once, and passing its return value to this.use?

Code example from that comment:

"use strict";

const lunr = require("lunr");
require("lunr-languages/lunr.stemmer.support")(lunr);
require("lunr-languages/lunr.multi")(lunr);
require("lunr-languages/lunr.it")(lunr);

let englishItalianSupport = lunr.multiLanguage('en', 'it'); // here

// > Access to the index for full text search
let fullTextIndex;

// > Generate the index for full text search
exports.regenerateFullTextIndex = function(documents) {

   fullTextIndex = lunr(function() {

      this.use(englishItalianSupport); // ...and here

      this.ref("id");
      this.field("title");
      this.field("body");

      const len = documents.length;
      for(let i = 0; i < len; ++i) {
         this.add({id: documents[i].id, title: documents[i].title, body: documents[i].text});
      }
   });
};

@weareoutman: Is above info enough for you to get rid of these warnings when building?