lunr.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Convenience function for instantiating a new lunr index and configuring it
  3. * with the default pipeline functions and the passed config function.
  4. *
  5. * When using this convenience function a new index will be created with the
  6. * following functions already in the pipeline:
  7. *
  8. * lunr.StopWordFilter - filters out any stop words before they enter the
  9. * index
  10. *
  11. * lunr.stemmer - stems the tokens before entering the index.
  12. *
  13. * Example:
  14. *
  15. * var idx = lunr(function () {
  16. * this.field('title', 10)
  17. * this.field('tags', 100)
  18. * this.field('body')
  19. *
  20. * this.ref('cid')
  21. *
  22. * this.pipeline.add(function () {
  23. * // some custom pipeline function
  24. * })
  25. *
  26. * })
  27. *
  28. * @param {Function} config A function that will be called with the new instance
  29. * of the lunr.Index as both its context and first parameter. It can be used to
  30. * customize the instance of new lunr.Index.
  31. * @namespace
  32. * @module
  33. * @returns {lunr.Index}
  34. *
  35. */
  36. var lunr = function (config) {
  37. var idx = new lunr.Index
  38. idx.pipeline.add(
  39. lunr.trimmer,
  40. lunr.stopWordFilter,
  41. lunr.stemmer
  42. )
  43. if (config) config.call(idx, idx)
  44. return idx
  45. }
  46. lunr.version = "@VERSION"