diff options
| author | Alejandro Soto <alejandro@34project.org> | 2025-09-13 15:01:06 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2025-09-13 15:01:06 -0600 |
| commit | f4fcda54638685899c730b3fa90a87d80d6dbef5 (patch) | |
| tree | 0737e627cce304c3a9c4e757bc5f6571a7456091 /sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js | |
| parent | d8b9cf1f61cc07d625f1c37ccc28adfd58918416 (diff) | |
| parent | 2c13119932765c6d788f08fb53abc244407c0d80 (diff) | |
Merge commit '6a7d3111b31e73fc66af5360149d41f690fbcaa4'
Diffstat (limited to 'sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js')
| -rw-r--r-- | sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js b/sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js new file mode 100644 index 0000000..90a7629 --- /dev/null +++ b/sysret.org/themes/tabi-lean/static/js/lunr/lunr.jp.js @@ -0,0 +1,120 @@ +/*! + * Lunr languages, `Japanese` language + * https://github.com/MihaiValentin/lunr-languages + * + * Copyright 2014, Chad Liu + * http://www.mozilla.org/MPL/ + */ +/*! + * based on + * Snowball JavaScript Library v0.3 + * http://code.google.com/p/urim/ + * http://snowball.tartarus.org/ + * + * Copyright 2010, Oleg Mazko + * http://www.mozilla.org/MPL/ + */ + +/** + * export the module via AMD, CommonJS or as a browser global + * Export code from https://github.com/umdjs/umd/blob/master/returnExports.js + */ +; +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(factory) + } else if (typeof exports === 'object') { + /** + * Node. Does not work with strict CommonJS, but + * only CommonJS-like environments that support module.exports, + * like Node. + */ + module.exports = factory() + } else { + // Browser globals (root is window) + factory()(root.lunr); + } +}(this, function() { + /** + * Just return a value to define the module export. + * This example returns an object, but the module + * can return a function as the exported value. + */ + return function(lunr) { + /* throw error if lunr is not yet included */ + if ('undefined' === typeof lunr) { + throw new Error('Lunr is not present. Please include / require Lunr before this script.'); + } + + /* throw error if lunr stemmer support is not yet included */ + if ('undefined' === typeof lunr.stemmerSupport) { + throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.'); + } + + /* register specific locale function */ + lunr.jp = function() { + this.pipeline.reset(); + this.pipeline.add( + lunr.jp.stopWordFilter, + lunr.jp.stemmer + ); + // change the tokenizer for japanese one + lunr.tokenizer = lunr.jp.tokenizer; + }; + var segmenter = new TinySegmenter(); // インスタンス生成 + + lunr.jp.tokenizer = function (obj) { + if (!arguments.length || obj == null || obj == undefined) return []; + if (Array.isArray(obj)) + return obj.map(function (t) { + return t.toLowerCase(); + }); + + var str = obj.toString().replace(/^\s+/, ''); + + for (var i = str.length - 1; i >= 0; i--) { + if (/\S/.test(str.charAt(i))) { + str = str.substring(0, i + 1); + break; + } + } + + var segs = segmenter.segment(str); // 単語の配列が返る + return segs + .filter(function (token) { + return !!token; + }) + .map(function (token) { + return token; + }); + }; + + /* lunr stemmer function */ + lunr.jp.stemmer = (function () { + /* TODO japanese stemmer */ + return function (word) { + return word; + }; + })(); + + lunr.Pipeline.registerFunction(lunr.jp.stemmer, 'stemmer-jp'); + + /* stop word filter function */ + lunr.jp.stopWordFilter = function(token) { + if (lunr.jp.stopWordFilter.stopWords.indexOf(token) === -1) { + return token; + } + }; + + lunr.jp.stopWordFilter.stopWords = new lunr.SortedSet(); + lunr.jp.stopWordFilter.stopWords.length = 45; + + // The space at the beginning is crucial: It marks the empty string + // as a stop word. lunr.js crashes during search when documents + // processed by the pipeline still contain the empty string. + // stopword for japanese is from http://www.ranks.nl/stopwords/japanese + lunr.jp.stopWordFilter.stopWords.elements = ' これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし'.split(' '); + lunr.Pipeline.registerFunction(lunr.jp.stopWordFilter, 'stopWordFilter-jp'); + }; +})) |
