hoelzro / lunr-mutable-indexes

Mutable indexes for lunr.js 2.1.x
MIT License
20 stars 4 forks source link

lunr.Pipeline.registerFunction undefined #2

Open acedward opened 6 years ago

acedward commented 6 years ago

@hoelzro Awesome project!

I was trying to get this working with multi-language support with: https://github.com/MihaiValentin/lunr-languages

And i'm hitting this error:

TypeError: Cannot read property 'registerFunction' of undefined
at */node_modules/lunr-languages/lunr.es.js:77:18

it fails here lunr.Pipeline.registerFunction(lunr.es.trimmer, 'trimmer-es'); I've digged a bit into your code, but haven't been able to find how fix this.

Any ideas / tips how to get this working?

Thanks!

acedward commented 6 years ago

I've got it working by adding

lunrMutable.Pipeline = lunr.Pipeline;
lunrMutable.generateStopWordFilter = lunr.generateStopWordFilter;

at lunr-mutable.js, I'm not sure this is a correct solution - perhaps the complete lunr interface should be exposed? e.g.,

Object.keys(lunr).forEach((key) => {
  if (!lunrMutable.hasOwnProperty(key)) {
    lunrMutable[key] = lunr[key];
  }
hoelzro commented 6 years ago

@acedward Thanks for the bug report! Would you mind posting your full code so I can have a look?

acedward commented 6 years ago

The crash occurs here

const lunr = require('lunr-mutable-indexes');
require('../../../node_modules/lunr-languages/lunr.stemmer.support')(lunr);
require('../../../node_modules/lunr-languages/lunr.es.js')(lunr);

Workaround: https://github.com/hoelzro/lunr-mutable-indexes/compare/master...acedward:master

Thanks

hoelzro commented 6 years ago

Ah, that makes sense - so what you'll want to do is pass the actual lunr library to those modules:

const lunr = require('lunr');
const lunrMutable = require('lunr-mutable-indexes');

require('lunr.stemmer.support')(lunr);
require('lunr.es.js')(lunr);

If that doesn't do the trick, I'll need to experiment a bit.