overwrite Backgrid.Extension.LunrFilter

125 views Asked by At
var lunrFilter1 = new Backgrid.Extension.LunrFilter({
  collection: pageableTerritories.fullCollection,
  placeholder: "Name",
  fields: {
    name: name
  },
  ref: 'id',
  wait: 150
});
$example2.prepend(lunrFilter1.render().el);
lunrFilter1.$el.css({float: "left", margin: "20px"});

It uses lunr.tokenizer from assest/js/lunr.js.

How can I overwrite/extend it ?

1

There are 1 answers

0
Oliver Nightingale On

The default tokenizer in lunr is just a function on the top level lunr name space.

Unfortunately there is no easy way to extend the tokeniser at the moment, it is possible to completely replace it with your own implementation though.

lunr.tokenizer = function (obj) {
  // your implementation here!
}

The existing implementation handles being passed strings, arrays of strings or nothing (null or undefined) and must return either an array of strings or an empty array. This array will then be processed by the rest of the text processing pipeline. If you satisfy those constraints lunr will be none the wiser that you swapped out the tokenizer and will continue to work as expected.

If there is a specific feature that is missing, or a bug that you have found, please open an issue on the Github project.