Debian Codegraph @

mkdocs/contrib/search/lunr-language/lunr.th.js

raw
1 /*!
2 * Lunr languages, `Thai` 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 /**
19 * export the module via AMD, CommonJS or as a browser global
20 * Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
21 */
22 ;
23 (function(root, factory) {
24 if (typeof define === 'function' && define.amd) {
25 // AMD. Register as an anonymous module.
26 define(factory)
27 } else if (typeof exports === 'object') {
28 /**
29 * Node. Does not work with strict CommonJS, but
30 * only CommonJS-like environments that support module.exports,
31 * like Node.
32 */
33 module.exports = factory()
34 } else {
35 // Browser globals (root is window)
36 factory()(root.lunr);
37 }
38 }(this, function() {
39 /**
40 * Just return a value to define the module export.
41 * This example returns an object, but the module
42 * can return a function as the exported value.
43 */
44 return function(lunr) {
45 /* throw error if lunr is not yet included */
46 if ('undefined' === typeof lunr) {
47 throw new Error('Lunr is not present. Please include / require Lunr before this script.');
48 }
49
50 /* throw error if lunr stemmer support is not yet included */
51 if ('undefined' === typeof lunr.stemmerSupport) {
52 throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
53 }
54
55 /*
56 Thai tokenization is the same to Japanense, which does not take into account spaces.
57 So, it uses the same logic to assign tokenization function due to different Lunr versions.
58 */
59 var isLunr2 = lunr.version[0] == "2";
60
61 /* register specific locale function */
62 lunr.th = function() {
63 this.pipeline.reset();
64 this.pipeline.add(
65 /*lunr.th.stopWordFilter,*/
66 lunr.th.trimmer
67 );
68
69 if (isLunr2) { // for lunr version 2.0.0
70 this.tokenizer = lunr.th.tokenizer;
71 } else {
72 if (lunr.tokenizer) { // for lunr version 0.6.0
73 lunr.tokenizer = lunr.th.tokenizer;
74 }
75 if (this.tokenizerFn) { // for lunr version 0.7.0 -> 1.0.0
76 this.tokenizerFn = lunr.th.tokenizer;
77 }
78 }
79 };
80
81 /* lunr trimmer function */
82 lunr.th.wordCharacters = "[\u0e00-\u0e7f]";
83 lunr.th.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.th.wordCharacters);
84 lunr.Pipeline.registerFunction(lunr.th.trimmer, 'trimmer-th');
85
86 var segmenter = lunr.wordcut;
87 segmenter.init();
88 lunr.th.tokenizer = function(obj) {
89 //console.log(obj);
90 if (!arguments.length || obj == null || obj == undefined) return []
91 if (Array.isArray(obj)) return obj.map(function(t) {
92 return isLunr2 ? new lunr.Token(t) : t
93 })
94
95 var str = obj.toString().replace(/^\s+/, '');
96 return segmenter.cut(str).split('|');
97 }
98 };
99 }))