Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Overwriting existing registered function" warning when creating multiple indexes #530

Open
khromov opened this issue Mar 8, 2024 · 0 comments

Comments

@khromov
Copy link

khromov commented Mar 8, 2024

👋 This is probably me something wrong but I couldn't find the answer in the docs. I'm creating multiple indexes and have a creator function for them, like:

export const createLunrIndex = (records: SearchRecords, type: string) => {
  return lunr(function () {
    this.field('title');
    
    // Adding my custom plugin
    this.use(trimmer);

I also wrote a simple trimmer plugin.

export const trimmer = (builder: Builder) => {
  const trimmerFunction = function (token) {
    return token.update(function (s) {
      const trimmed = s
        .replace(/^[\.,;:()\s]+/, '')
        .replace(/[\.,;:()\s]+$/, '');
      return `${trimmed}`;
    });
  };

  // Register the pipeline function so the index can be serialised
  lunr.Pipeline.registerFunction(trimmerFunction, 'trimmerCustom');

  // Add the pipeline function to both the indexing pipeline and the search pipeline
  builder.pipeline.add(trimmerFunction);
  builder.searchPipeline.add(trimmerFunction);
};

Then I initialize two indexes:

const dogIndex = createLunrIndex(records1, 'dogs');
const catIndex = createLunrIndex(records1, 'cats');

I would expect that calling .use would init the plugin once per index, but instead I get:

Overwriting existing registered function: trimmerCustom

Is there some way to get around this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant