lunr example

by toubia95

HTML

<script src="https://unpkg.com/lunr/lunr.js"></script>

JavaScript

// https://lunrjs.com/guides/getting_started.html

var documents = [{
  //"name": "Lunr",
  "ref": "Like Solr, but much smaller, and not as bright."
}, {
  //"name": "React",
  "ref": "A JavaScript library for building user interfaces."
}, {
  //"name": "Lodash",
  "ref": "A modern JavaScript utility library delivering modularity, performance & extras."
}]

var idx = lunr(function () {
  this.ref('ref') // this.ref('name')
  this.field('ref') // this.ref('text')

  documents.forEach(function (doc) {
    this.add(doc)
  }, this)
})

console.log(idx.search("library"));