elasticlunr.js icon indicating copy to clipboard operation
elasticlunr.js copied to clipboard

Ability to use field in tokenization functions

Open msotnikov opened this issue 4 years ago • 0 comments

Add the field value into pipeline function (token, i, tokens, field)

Inspired https://lunrjs.com/guides/customising.html#pipeline-functions

Expample usage:

  const skipField = function (fieldName, fn) {
    return function (token, i, tokens, field) {
      if (field === fieldName) {
        return token
      }

      return fn(token, i, tokens)
    }
  }
const selectiveStopWordfilter = skipField('fieldNameToSkip', elasticlunr.en.stopWordFilter)
  builder.pipeline.add(
    elasticlunr.trimmer,
    selectiveStopWordfilter,
)

msotnikov avatar Aug 13 '20 21:08 msotnikov