lunr.vi.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*!
  2. * Lunr languages, `Vietnamese` language
  3. * https://github.com/MihaiValentin/lunr-languages
  4. *
  5. * Copyright 2017, Keerati Thiwanruk
  6. * http://www.mozilla.org/MPL/
  7. */
  8. /*!
  9. * based on
  10. * Snowball JavaScript Library v0.3
  11. * http://code.google.com/p/urim/
  12. * http://snowball.tartarus.org/
  13. *
  14. * Copyright 2010, Oleg Mazko
  15. * http://www.mozilla.org/MPL/
  16. */
  17. /**
  18. * export the module via AMD, CommonJS or as a browser global
  19. * Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
  20. */
  21. ;
  22. (function(root, factory) {
  23. if (typeof define === 'function' && define.amd) {
  24. // AMD. Register as an anonymous module.
  25. define(factory)
  26. } else if (typeof exports === 'object') {
  27. /**
  28. * Node. Does not work with strict CommonJS, but
  29. * only CommonJS-like environments that support module.exports,
  30. * like Node.
  31. */
  32. module.exports = factory()
  33. } else {
  34. // Browser globals (root is window)
  35. factory()(root.lunr);
  36. }
  37. }(this, function() {
  38. /**
  39. * Just return a value to define the module export.
  40. * This example returns an object, but the module
  41. * can return a function as the exported value.
  42. */
  43. return function(lunr) {
  44. /* throw error if lunr is not yet included */
  45. if ('undefined' === typeof lunr) {
  46. throw new Error('Lunr is not present. Please include / require Lunr before this script.');
  47. }
  48. /* throw error if lunr stemmer support is not yet included */
  49. if ('undefined' === typeof lunr.stemmerSupport) {
  50. throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
  51. }
  52. /* register specific locale function */
  53. lunr.vi = function() {
  54. this.pipeline.reset();
  55. this.pipeline.add(
  56. lunr.vi.stopWordFilter,
  57. lunr.vi.trimmer
  58. );
  59. };
  60. /* lunr trimmer function */
  61. lunr.vi.wordCharacters = "[" +
  62. "A-Za-z" +
  63. "\u0300\u0350" + // dấu huyền
  64. "\u0301\u0351" + // dấu sắc
  65. "\u0309" + // dấu hỏi
  66. "\u0323" + // dấu nặng
  67. "\u0303\u0343" + // dấu ngã
  68. "\u00C2\u00E2" + // Â
  69. "\u00CA\u00EA" + // Ê
  70. "\u00D4\u00F4" + // Ô
  71. "\u0102-\u0103" + // Ă
  72. "\u0110-\u0111" + // Đ
  73. "\u01A0-\u01A1" + // Ơ
  74. "\u01AF-\u01B0" + // Ư
  75. "]";
  76. lunr.vi.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.vi.wordCharacters);
  77. lunr.Pipeline.registerFunction(lunr.vi.trimmer, 'trimmer-vi');
  78. lunr.vi.stopWordFilter = lunr.generateStopWordFilter('là cái nhưng mà'.split(' '));
  79. };
  80. }))