search_perf.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. suite('search', function () {
  2. var documents = [{
  3. id: 'a',
  4. title: 'Mr. Green kills Colonel Mustard',
  5. body: 'Mr. Green killed Colonel Mustard in the study with the candlestick. Mr. Green is not a very nice fellow.',
  6. wordCount: 19
  7. },{
  8. id: 'b',
  9. title: 'Plumb waters plant',
  10. body: 'Professor Plumb has a green plant in his study',
  11. wordCount: 9
  12. },{
  13. id: 'c',
  14. title: 'Scarlett helps Professor',
  15. body: 'Miss Scarlett watered Professor Plumbs green plant while he was away from his office last week.',
  16. wordCount: 16
  17. }]
  18. var idx = lunr(function () {
  19. this.ref('id')
  20. this.field('title')
  21. this.field('body')
  22. documents.forEach(function (doc) {
  23. this.add(doc)
  24. }, this)
  25. })
  26. this.add('single term', function () {
  27. idx.search('green')
  28. })
  29. this.add('multi term', function () {
  30. idx.search('green plant')
  31. })
  32. this.add('trailing wildcard', function () {
  33. idx.search('pl*')
  34. })
  35. this.add('leading wildcard', function () {
  36. idx.search('*ant')
  37. })
  38. this.add('contained wildcard', function () {
  39. idx.search('p*t')
  40. })
  41. this.add('with field', function () {
  42. idx.search('title:plant')
  43. })
  44. this.add('edit distance', function () {
  45. idx.search('plint~2')
  46. })
  47. this.add('typeahead', function () {
  48. idx.query(function (q) {
  49. q.term("pl", { boost: 100, usePipeline: true })
  50. q.term("pl", { boost: 10, usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING })
  51. q.term("pl", { boost: 1, editDistance: 1 })
  52. })
  53. })
  54. this.add('negated query', function () {
  55. idx.search('-plant')
  56. })
  57. this.add('required term', function () {
  58. idx.search('green +plant')
  59. })
  60. })