Closed crystalfp closed 6 years ago
Hi @crystalfp!
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
? Maybe that would clear up the error. To clarify, this is what I mean:
"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});
}
});
};
Thanks for the suggestion! But unfortunately the warning is still here: Overwriting existing registered function: lunr-multi-trimmer-en-it
.
Now I try to delete the index before regenerating it to see if anything change.
Apparently deleting the index before regenerating it prevents the small warning. That is:
fullTextIndex = {};
fullTextIndex = lunr(function() {...})
Strange, but it works. Thanks!
I'm using lunr v2 to index a hundred documents (Italian and English). Each time the user requests a full text search I rebuild the index if the set of documents has changed. The only small problem is that on subsequent requests I receive the warning:
Overwriting existing registered function: lunr-multi-trimmer-en-it
. Here is the code:The calling function is very simple (hasFileListChanged is set true every time I modify the set of documents:
Seems that the main
lunr()
function not only recreates the index, but also registers the language related function every time. I don't see any workaround to the warning message. Yes, I can simply ignore it, but sure a user will notice immediately. Maybe there is another method to delete and recreate the index.Thanks! mario