yeraydiazdiaz / lunr.py

A Python implementation of Lunr.js 🌖
http://lunr.readthedocs.io
MIT License
187 stars 16 forks source link

Pipeline should have an `insert` and/or a `replace` method #155

Open dhdaines opened 1 month ago

dhdaines commented 1 month ago

Because the language-specific trimmers are seriously defective at the moment (see #149) in both lunr.py and lunr.js (they don't include \w for instance), I need to be able to replace them. Unfortunately this is difficult to do robustly, because the API (which is inherited from lunr.js, so it's not your fault!) only has add, remove, before and after.

I would like to be able to do:

builder.pipeline.replace(
    builder.pipeline.registered_functions["lunr-multi-trimmer-fr"], trimmer.trimmer
)

But instead I have to do this:

builder.pipeline.remove(
    builder.pipeline.registered_functions["lunr-multi-trimmer-fr"]
)
builder.pipeline.before(
    builder.pipeline.registered_functions["stopWordFilter-fr"], trimmer.trimmer
)