lunr.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * A convenience function for configuring and constructing
  3. * a new lunr Index.
  4. *
  5. * A lunr.Builder instance is created and the pipeline setup
  6. * with a trimmer, stop word filter and stemmer.
  7. *
  8. * This builder object is yielded to the configuration function
  9. * that is passed as a parameter, allowing the list of fields
  10. * and other builder parameters to be customised.
  11. *
  12. * All documents _must_ be added within the passed config function.
  13. *
  14. * @example
  15. * var idx = lunr(function () {
  16. * this.field('title')
  17. * this.field('body')
  18. * this.ref('id')
  19. *
  20. * documents.forEach(function (doc) {
  21. * this.add(doc)
  22. * }, this)
  23. * })
  24. *
  25. * @see {@link lunr.Builder}
  26. * @see {@link lunr.Pipeline}
  27. * @see {@link lunr.trimmer}
  28. * @see {@link lunr.stopWordFilter}
  29. * @see {@link lunr.stemmer}
  30. * @namespace {function} lunr
  31. */
  32. var lunr = function (config) {
  33. var builder = new lunr.Builder
  34. builder.pipeline.add(
  35. lunr.trimmer,
  36. lunr.stopWordFilter,
  37. lunr.stemmer
  38. )
  39. builder.searchPipeline.add(
  40. lunr.stemmer
  41. )
  42. config.call(builder, builder)
  43. return builder.build()
  44. }
  45. lunr.version = "@VERSION"