Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/koirand/pulp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorkoirand <koirand.jp@gmail.com>2018-10-29 17:50:33 +0300
committerkoirand <koirand.jp@gmail.com>2018-10-29 17:50:33 +0300
commitd3d0669c0dac7fc683c5a8382be4d9f855a0b2aa (patch)
tree15661cea339e976ecbdfd94d8ad16b1cd8c4afc7 /static
parentfd5983ac6859f3a8a0037d9b97f18c2b7779bdc2 (diff)
Changed full-text search library from lune.js to fuse.js
Diffstat (limited to 'static')
-rw-r--r--static/js/fuse.min.js9
-rw-r--r--static/js/lunr.ja.js188
-rw-r--r--static/js/lunr.js3484
-rw-r--r--static/js/lunr.stemmer.support.js304
-rw-r--r--static/js/search.js59
-rw-r--r--static/js/tinyseg.js207
6 files changed, 28 insertions, 4223 deletions
diff --git a/static/js/fuse.min.js b/static/js/fuse.min.js
new file mode 100644
index 0000000..0c7ae7d
--- /dev/null
+++ b/static/js/fuse.min.js
@@ -0,0 +1,9 @@
+/*!
+ * Fuse.js v3.2.1 - Lightweight fuzzy-search (http://fusejs.io)
+ *
+ * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me)
+ * All Rights Reserved. Apache Software License 2.0
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Fuse",[],t):"object"==typeof exports?exports.Fuse=t():e.Fuse=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=8)}([function(e,t,r){"use strict";e.exports=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(5),a=r(7),s=r(4),c=function(){function e(t,r){var o=r.location,i=void 0===o?0:o,a=r.distance,c=void 0===a?100:a,h=r.threshold,l=void 0===h?.6:h,u=r.maxPatternLength,f=void 0===u?32:u,d=r.isCaseSensitive,v=void 0!==d&&d,p=r.tokenSeparator,g=void 0===p?/ +/g:p,y=r.findAllMatches,m=void 0!==y&&y,k=r.minMatchCharLength,x=void 0===k?1:k;n(this,e),this.options={location:i,distance:c,threshold:l,maxPatternLength:f,isCaseSensitive:v,tokenSeparator:g,findAllMatches:m,minMatchCharLength:x},this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.pattern.length<=f&&(this.patternAlphabet=s(this.pattern))}return o(e,[{key:"search",value:function(e){if(this.options.isCaseSensitive||(e=e.toLowerCase()),this.pattern===e)return{isMatch:!0,score:0,matchedIndices:[[0,e.length-1]]};var t=this.options,r=t.maxPatternLength,n=t.tokenSeparator;if(this.pattern.length>r)return i(e,this.pattern,n);var o=this.options,s=o.location,c=o.distance,h=o.threshold,l=o.findAllMatches,u=o.minMatchCharLength;return a(e,this.pattern,this.patternAlphabet,{location:s,distance:c,threshold:h,findAllMatches:l,minMatchCharLength:u})}}]),e}();e.exports=c},function(e,t,r){"use strict";var n=r(0),o=function e(t,r,o){if(r){var i=r.indexOf("."),a=r,s=null;-1!==i&&(a=r.slice(0,i),s=r.slice(i+1));var c=t[a];if(null!==c&&void 0!==c)if(s||"string"!=typeof c&&"number"!=typeof c)if(n(c))for(var h=0,l=c.length;h<l;h+=1)e(c[h],s,o);else s&&e(c,s,o);else o.push(c.toString())}else o.push(t);return o};e.exports=function(e,t){return o(e,t,[])}},function(e,t,r){"use strict";e.exports=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=[],n=-1,o=-1,i=0,a=e.length;i<a;i+=1){var s=e[i];s&&-1===n?n=i:s||-1===n||(o=i-1,o-n+1>=t&&r.push([n,o]),n=-1)}return e[i-1]&&i-n>=t&&r.push([n,i-1]),r}},function(e,t,r){"use strict";e.exports=function(e){for(var t={},r=e.length,n=0;n<r;n+=1)t[e.charAt(n)]=0;for(var o=0;o<r;o+=1)t[e.charAt(o)]|=1<<r-o-1;return t}},function(e,t,r){"use strict";e.exports=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,n=new RegExp(t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&").replace(r,"|")),o=e.match(n),i=!!o,a=[];if(i)for(var s=0,c=o.length;s<c;s+=1){var h=o[s];a.push([e.indexOf(h),h.length-1])}return{score:i?.5:1,isMatch:i,matchedIndices:a}}},function(e,t,r){"use strict";e.exports=function(e,t){var r=t.errors,n=void 0===r?0:r,o=t.currentLocation,i=void 0===o?0:o,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?100:c,l=n/e.length,u=Math.abs(s-i);return h?l+u/h:u?1:l}},function(e,t,r){"use strict";var n=r(6),o=r(3);e.exports=function(e,t,r,i){for(var a=i.location,s=void 0===a?0:a,c=i.distance,h=void 0===c?100:c,l=i.threshold,u=void 0===l?.6:l,f=i.findAllMatches,d=void 0!==f&&f,v=i.minMatchCharLength,p=void 0===v?1:v,g=s,y=e.length,m=u,k=e.indexOf(t,g),x=t.length,S=[],M=0;M<y;M+=1)S[M]=0;if(-1!==k){var b=n(t,{errors:0,currentLocation:k,expectedLocation:g,distance:h});if(m=Math.min(b,m),-1!==(k=e.lastIndexOf(t,g+x))){var _=n(t,{errors:0,currentLocation:k,expectedLocation:g,distance:h});m=Math.min(_,m)}}k=-1;for(var L=[],w=1,A=x+y,C=1<<x-1,I=0;I<x;I+=1){for(var O=0,F=A;O<F;){n(t,{errors:I,currentLocation:g+F,expectedLocation:g,distance:h})<=m?O=F:A=F,F=Math.floor((A-O)/2+O)}A=F;var P=Math.max(1,g-F+1),j=d?y:Math.min(g+F,y)+x,z=Array(j+2);z[j+1]=(1<<I)-1;for(var T=j;T>=P;T-=1){var E=T-1,K=r[e.charAt(E)];if(K&&(S[E]=1),z[T]=(z[T+1]<<1|1)&K,0!==I&&(z[T]|=(L[T+1]|L[T])<<1|1|L[T+1]),z[T]&C&&(w=n(t,{errors:I,currentLocation:E,expectedLocation:g,distance:h}))<=m){if(m=w,(k=E)<=g)break;P=Math.max(1,2*g-k)}}if(n(t,{errors:I+1,currentLocation:g,expectedLocation:g,distance:h})>m)break;L=z}return{isMatch:k>=0,score:0===w?.001:w,matchedIndices:o(S,p)}}},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(1),a=r(2),s=r(0),c=function(){function e(t,r){var o=r.location,i=void 0===o?0:o,s=r.distance,c=void 0===s?100:s,h=r.threshold,l=void 0===h?.6:h,u=r.maxPatternLength,f=void 0===u?32:u,d=r.caseSensitive,v=void 0!==d&&d,p=r.tokenSeparator,g=void 0===p?/ +/g:p,y=r.findAllMatches,m=void 0!==y&&y,k=r.minMatchCharLength,x=void 0===k?1:k,S=r.id,M=void 0===S?null:S,b=r.keys,_=void 0===b?[]:b,L=r.shouldSort,w=void 0===L||L,A=r.getFn,C=void 0===A?a:A,I=r.sortFn,O=void 0===I?function(e,t){return e.score-t.score}:I,F=r.tokenize,P=void 0!==F&&F,j=r.matchAllTokens,z=void 0!==j&&j,T=r.includeMatches,E=void 0!==T&&T,K=r.includeScore,$=void 0!==K&&K,J=r.verbose,N=void 0!==J&&J;n(this,e),this.options={location:i,distance:c,threshold:l,maxPatternLength:f,isCaseSensitive:v,tokenSeparator:g,findAllMatches:m,minMatchCharLength:x,id:M,keys:_,includeMatches:E,includeScore:$,shouldSort:w,getFn:C,sortFn:O,verbose:N,tokenize:P,matchAllTokens:z},this.setCollection(t)}return o(e,[{key:"setCollection",value:function(e){return this.list=e,e}},{key:"search",value:function(e){this._log('---------\nSearch pattern: "'+e+'"');var t=this._prepareSearchers(e),r=t.tokenSearchers,n=t.fullSearcher,o=this._search(r,n),i=o.weights,a=o.results;return this._computeScore(i,a),this.options.shouldSort&&this._sort(a),this._format(a)}},{key:"_prepareSearchers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=[];if(this.options.tokenize)for(var r=e.split(this.options.tokenSeparator),n=0,o=r.length;n<o;n+=1)t.push(new i(r[n],this.options));return{tokenSearchers:t,fullSearcher:new i(e,this.options)}}},{key:"_search",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],r=this.list,n={},o=[];if("string"==typeof r[0]){for(var i=0,a=r.length;i<a;i+=1)this._analyze({key:"",value:r[i],record:i,index:i},{resultMap:n,results:o,tokenSearchers:e,fullSearcher:t});return{weights:null,results:o}}for(var s={},c=0,h=r.length;c<h;c+=1)for(var l=r[c],u=0,f=this.options.keys.length;u<f;u+=1){var d=this.options.keys[u];if("string"!=typeof d){if(s[d.name]={weight:1-d.weight||1},d.weight<=0||d.weight>1)throw new Error("Key weight has to be > 0 and <= 1");d=d.name}else s[d]={weight:1};this._analyze({key:d,value:this.options.getFn(l,d),record:l,index:c},{resultMap:n,results:o,tokenSearchers:e,fullSearcher:t})}return{weights:s,results:o}}},{key:"_analyze",value:function(e,t){var r=e.key,n=e.arrayIndex,o=void 0===n?-1:n,i=e.value,a=e.record,c=e.index,h=t.tokenSearchers,l=void 0===h?[]:h,u=t.fullSearcher,f=void 0===u?[]:u,d=t.resultMap,v=void 0===d?{}:d,p=t.results,g=void 0===p?[]:p;if(void 0!==i&&null!==i){var y=!1,m=-1,k=0;if("string"==typeof i){this._log("\nKey: "+(""===r?"-":r));var x=f.search(i);if(this._log('Full text: "'+i+'", score: '+x.score),this.options.tokenize){for(var S=i.split(this.options.tokenSeparator),M=[],b=0;b<l.length;b+=1){var _=l[b];this._log('\nPattern: "'+_.pattern+'"');for(var L=!1,w=0;w<S.length;w+=1){var A=S[w],C=_.search(A),I={};C.isMatch?(I[A]=C.score,y=!0,L=!0,M.push(C.score)):(I[A]=1,this.options.matchAllTokens||M.push(1)),this._log('Token: "'+A+'", score: '+I[A])}L&&(k+=1)}m=M[0];for(var O=M.length,F=1;F<O;F+=1)m+=M[F];m/=O,this._log("Token score average:",m)}var P=x.score;m>-1&&(P=(P+m)/2),this._log("Score average:",P);var j=!this.options.tokenize||!this.options.matchAllTokens||k>=l.length;if(this._log("\nCheck Matches: "+j),(y||x.isMatch)&&j){var z=v[c];z?z.output.push({key:r,arrayIndex:o,value:i,score:P,matchedIndices:x.matchedIndices}):(v[c]={item:a,output:[{key:r,arrayIndex:o,value:i,score:P,matchedIndices:x.matchedIndices}]},g.push(v[c]))}}else if(s(i))for(var T=0,E=i.length;T<E;T+=1)this._analyze({key:r,arrayIndex:T,value:i[T],record:a,index:c},{resultMap:v,results:g,tokenSearchers:l,fullSearcher:f})}}},{key:"_computeScore",value:function(e,t){this._log("\n\nComputing score:\n");for(var r=0,n=t.length;r<n;r+=1){for(var o=t[r].output,i=o.length,a=1,s=1,c=0;c<i;c+=1){var h=e?e[o[c].key].weight:1,l=1===h?o[c].score:o[c].score||.001,u=l*h;1!==h?s=Math.min(s,u):(o[c].nScore=u,a*=u)}t[r].score=1===s?a:s,this._log(t[r])}}},{key:"_sort",value:function(e){this._log("\n\nSorting...."),e.sort(this.options.sortFn)}},{key:"_format",value:function(e){var t=[];this.options.verbose&&this._log("\n\nOutput:\n\n",JSON.stringify(e));var r=[];this.options.includeMatches&&r.push(function(e,t){var r=e.output;t.matches=[];for(var n=0,o=r.length;n<o;n+=1){var i=r[n];if(0!==i.matchedIndices.length){var a={indices:i.matchedIndices,value:i.value};i.key&&(a.key=i.key),i.hasOwnProperty("arrayIndex")&&i.arrayIndex>-1&&(a.arrayIndex=i.arrayIndex),t.matches.push(a)}}}),this.options.includeScore&&r.push(function(e,t){t.score=e.score});for(var n=0,o=e.length;n<o;n+=1){var i=e[n];if(this.options.id&&(i.item=this.options.getFn(i.item,this.options.id)[0]),r.length){for(var a={item:i.item},s=0,c=r.length;s<c;s+=1)r[s](i,a);t.push(a)}else t.push(i.item)}return t}},{key:"_log",value:function(){if(this.options.verbose){var e;(e=console).log.apply(e,arguments)}}}]),e}();e.exports=c}])}); \ No newline at end of file
diff --git a/static/js/lunr.ja.js b/static/js/lunr.ja.js
deleted file mode 100644
index 44eb411..0000000
--- a/static/js/lunr.ja.js
+++ /dev/null
@@ -1,188 +0,0 @@
-/*!
- * 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.');
- }
-
- /*
- Japanese tokenization is trickier, since it does not
- take into account spaces.
- Since the tokenization function is represented different
- internally for each of the Lunr versions, this had to be done
- in order to try to try to pick the best way of doing this based
- on the Lunr version
- */
- var isLunr2 = lunr.version[0] == "2";
-
- /* register specific locale function */
- lunr.ja = function() {
- this.pipeline.reset();
- this.pipeline.add(
- lunr.ja.trimmer,
- lunr.ja.stopWordFilter,
- lunr.ja.stemmer
- );
-
- // change the tokenizer for japanese one
- if (isLunr2) { // for lunr version 2.0.0
- this.tokenizer = lunr.ja.tokenizer;
- } else {
- if (lunr.tokenizer) { // for lunr version 0.6.0
- lunr.tokenizer = lunr.ja.tokenizer;
- }
- if (this.tokenizerFn) { // for lunr version 0.7.0 -> 1.0.0
- this.tokenizerFn = lunr.ja.tokenizer;
- }
- }
- };
- var segmenter = new lunr.TinySegmenter(); // インスタンス生成
-
- lunr.ja.tokenizer = function(obj) {
- var i;
- var str;
- var len;
- var segs;
- var tokens;
- var char;
- var sliceLength;
- var sliceStart;
- var sliceEnd;
- var segStart;
-
- if (!arguments.length || obj == null || obj == undefined)
- return [];
-
- if (Array.isArray(obj)) {
- return obj.map(
- function(t) {
- return isLunr2 ? new lunr.Token(t.toLowerCase()) : t.toLowerCase();
- }
- );
- }
-
- str = obj.toString().toLowerCase().replace(/^\s+/, '');
- for (i = str.length - 1; i >= 0; i--) {
- if (/\S/.test(str.charAt(i))) {
- str = str.substring(0, i + 1);
- break;
- }
- }
-
- tokens = [];
- len = str.length;
- for (sliceEnd = 0, sliceStart = 0; sliceEnd <= len; sliceEnd++) {
- char = str.charAt(sliceEnd);
- sliceLength = sliceEnd - sliceStart;
-
- if ((char.match(/\s/) || sliceEnd == len)) {
- if (sliceLength > 0) {
- segs = segmenter.segment(str.slice(sliceStart, sliceEnd)).filter(
- function(token) {
- return !!token;
- }
- );
-
- segStart = sliceStart;
- for (i = 0; i < segs.length; i++) {
- if (isLunr2) {
- tokens.push(
- new lunr.Token(
- segs[i], {
- position: [segStart, segs[i].length],
- index: tokens.length
- }
- )
- );
- } else {
- tokens.push(segs[i]);
- }
- segStart += segs[i].length;
- }
- }
-
- sliceStart = sliceEnd + 1;
- }
- }
-
- return tokens;
- }
-
- /* lunr stemmer function */
- lunr.ja.stemmer = (function() {
-
- /* TODO japanese stemmer */
- return function(word) {
- return word;
- }
- })();
- lunr.Pipeline.registerFunction(lunr.ja.stemmer, 'stemmer-ja');
-
- /* lunr trimmer function */
- lunr.ja.wordCharacters = "一二三四五六七八九十百千万億兆一-龠々〆ヵヶぁ-んァ-ヴーア-ン゙a-zA-Za-zA-Z0-90-9";
- lunr.ja.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.ja.wordCharacters);
- lunr.Pipeline.registerFunction(lunr.ja.trimmer, 'trimmer-ja');
-
- /* lunr stop word filter. see http://www.ranks.nl/stopwords/japanese */
- lunr.ja.stopWordFilter = lunr.generateStopWordFilter(
- 'これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし'.split(' '));
- lunr.Pipeline.registerFunction(lunr.ja.stopWordFilter, 'stopWordFilter-ja');
-
- // alias ja => jp for backward-compatibility.
- // jp is the country code, while ja is the language code
- // a new lunr.ja.js has been created, but in order to
- // keep the backward compatibility, we'll leave the lunr.jp.js
- // here for a while, and just make it use the new lunr.ja.js
- lunr.jp = lunr.ja;
- lunr.Pipeline.registerFunction(lunr.jp.stemmer, 'stemmer-jp');
- lunr.Pipeline.registerFunction(lunr.jp.trimmer, 'trimmer-jp');
- lunr.Pipeline.registerFunction(lunr.jp.stopWordFilter, 'stopWordFilter-jp');
- };
-})) \ No newline at end of file
diff --git a/static/js/lunr.js b/static/js/lunr.js
deleted file mode 100644
index 8f0c4a1..0000000
--- a/static/js/lunr.js
+++ /dev/null
@@ -1,3484 +0,0 @@
-/**
- * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.3
- * Copyright (C) 2018 Oliver Nightingale
- * @license MIT
- */
-
-;(function(){
-
-/**
- * A convenience function for configuring and constructing
- * a new lunr Index.
- *
- * A lunr.Builder instance is created and the pipeline setup
- * with a trimmer, stop word filter and stemmer.
- *
- * This builder object is yielded to the configuration function
- * that is passed as a parameter, allowing the list of fields
- * and other builder parameters to be customised.
- *
- * All documents _must_ be added within the passed config function.
- *
- * @example
- * var idx = lunr(function () {
- * this.field('title')
- * this.field('body')
- * this.ref('id')
- *
- * documents.forEach(function (doc) {
- * this.add(doc)
- * }, this)
- * })
- *
- * @see {@link lunr.Builder}
- * @see {@link lunr.Pipeline}
- * @see {@link lunr.trimmer}
- * @see {@link lunr.stopWordFilter}
- * @see {@link lunr.stemmer}
- * @namespace {function} lunr
- */
-var lunr = function (config) {
- var builder = new lunr.Builder
-
- builder.pipeline.add(
- lunr.trimmer,
- lunr.stopWordFilter,
- lunr.stemmer
- )
-
- builder.searchPipeline.add(
- lunr.stemmer
- )
-
- config.call(builder, builder)
- return builder.build()
-}
-
-lunr.version = "2.3.3"
-/*!
- * lunr.utils
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * A namespace containing utils for the rest of the lunr library
- * @namespace lunr.utils
- */
-lunr.utils = {}
-
-/**
- * Print a warning message to the console.
- *
- * @param {String} message The message to be printed.
- * @memberOf lunr.utils
- * @function
- */
-lunr.utils.warn = (function (global) {
- /* eslint-disable no-console */
- return function (message) {
- if (global.console && console.warn) {
- console.warn(message)
- }
- }
- /* eslint-enable no-console */
-})(this)
-
-/**
- * Convert an object to a string.
- *
- * In the case of `null` and `undefined` the function returns
- * the empty string, in all other cases the result of calling
- * `toString` on the passed object is returned.
- *
- * @param {Any} obj The object to convert to a string.
- * @return {String} string representation of the passed object.
- * @memberOf lunr.utils
- */
-lunr.utils.asString = function (obj) {
- if (obj === void 0 || obj === null) {
- return ""
- } else {
- return obj.toString()
- }
-}
-
-/**
- * Clones an object.
- *
- * Will create a copy of an existing object such that any mutations
- * on the copy cannot affect the original.
- *
- * Only shallow objects are supported, passing a nested object to this
- * function will cause a TypeError.
- *
- * Objects with primitives, and arrays of primitives are supported.
- *
- * @param {Object} obj The object to clone.
- * @return {Object} a clone of the passed object.
- * @throws {TypeError} when a nested object is passed.
- * @memberOf Utils
- */
-lunr.utils.clone = function (obj) {
- if (obj === null || obj === undefined) {
- return obj
- }
-
- var clone = Object.create(null),
- keys = Object.keys(obj)
-
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i],
- val = obj[key]
-
- if (Array.isArray(val)) {
- clone[key] = val.slice()
- continue
- }
-
- if (typeof val === 'string' ||
- typeof val === 'number' ||
- typeof val === 'boolean') {
- clone[key] = val
- continue
- }
-
- throw new TypeError("clone is not deep and does not support nested objects")
- }
-
- return clone
-}
-lunr.FieldRef = function (docRef, fieldName, stringValue) {
- this.docRef = docRef
- this.fieldName = fieldName
- this._stringValue = stringValue
-}
-
-lunr.FieldRef.joiner = "/"
-
-lunr.FieldRef.fromString = function (s) {
- var n = s.indexOf(lunr.FieldRef.joiner)
-
- if (n === -1) {
- throw "malformed field ref string"
- }
-
- var fieldRef = s.slice(0, n),
- docRef = s.slice(n + 1)
-
- return new lunr.FieldRef (docRef, fieldRef, s)
-}
-
-lunr.FieldRef.prototype.toString = function () {
- if (this._stringValue == undefined) {
- this._stringValue = this.fieldName + lunr.FieldRef.joiner + this.docRef
- }
-
- return this._stringValue
-}
-/*!
- * lunr.Set
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * A lunr set.
- *
- * @constructor
- */
-lunr.Set = function (elements) {
- this.elements = Object.create(null)
-
- if (elements) {
- this.length = elements.length
-
- for (var i = 0; i < this.length; i++) {
- this.elements[elements[i]] = true
- }
- } else {
- this.length = 0
- }
-}
-
-/**
- * A complete set that contains all elements.
- *
- * @static
- * @readonly
- * @type {lunr.Set}
- */
-lunr.Set.complete = {
- intersect: function (other) {
- return other
- },
-
- union: function (other) {
- return other
- },
-
- contains: function () {
- return true
- }
-}
-
-/**
- * An empty set that contains no elements.
- *
- * @static
- * @readonly
- * @type {lunr.Set}
- */
-lunr.Set.empty = {
- intersect: function () {
- return this
- },
-
- union: function (other) {
- return other
- },
-
- contains: function () {
- return false
- }
-}
-
-/**
- * Returns true if this set contains the specified object.
- *
- * @param {object} object - Object whose presence in this set is to be tested.
- * @returns {boolean} - True if this set contains the specified object.
- */
-lunr.Set.prototype.contains = function (object) {
- return !!this.elements[object]
-}
-
-/**
- * Returns a new set containing only the elements that are present in both
- * this set and the specified set.
- *
- * @param {lunr.Set} other - set to intersect with this set.
- * @returns {lunr.Set} a new set that is the intersection of this and the specified set.
- */
-
-lunr.Set.prototype.intersect = function (other) {
- var a, b, elements, intersection = []
-
- if (other === lunr.Set.complete) {
- return this
- }
-
- if (other === lunr.Set.empty) {
- return other
- }
-
- if (this.length < other.length) {
- a = this
- b = other
- } else {
- a = other
- b = this
- }
-
- elements = Object.keys(a.elements)
-
- for (var i = 0; i < elements.length; i++) {
- var element = elements[i]
- if (element in b.elements) {
- intersection.push(element)
- }
- }
-
- return new lunr.Set (intersection)
-}
-
-/**
- * Returns a new set combining the elements of this and the specified set.
- *
- * @param {lunr.Set} other - set to union with this set.
- * @return {lunr.Set} a new set that is the union of this and the specified set.
- */
-
-lunr.Set.prototype.union = function (other) {
- if (other === lunr.Set.complete) {
- return lunr.Set.complete
- }
-
- if (other === lunr.Set.empty) {
- return this
- }
-
- return new lunr.Set(Object.keys(this.elements).concat(Object.keys(other.elements)))
-}
-/**
- * A function to calculate the inverse document frequency for
- * a posting. This is shared between the builder and the index
- *
- * @private
- * @param {object} posting - The posting for a given term
- * @param {number} documentCount - The total number of documents.
- */
-lunr.idf = function (posting, documentCount) {
- var documentsWithTerm = 0
-
- for (var fieldName in posting) {
- if (fieldName == '_index') continue // Ignore the term index, its not a field
- documentsWithTerm += Object.keys(posting[fieldName]).length
- }
-
- var x = (documentCount - documentsWithTerm + 0.5) / (documentsWithTerm + 0.5)
-
- return Math.log(1 + Math.abs(x))
-}
-
-/**
- * A token wraps a string representation of a token
- * as it is passed through the text processing pipeline.
- *
- * @constructor
- * @param {string} [str=''] - The string token being wrapped.
- * @param {object} [metadata={}] - Metadata associated with this token.
- */
-lunr.Token = function (str, metadata) {
- this.str = str || ""
- this.metadata = metadata || {}
-}
-
-/**
- * Returns the token string that is being wrapped by this object.
- *
- * @returns {string}
- */
-lunr.Token.prototype.toString = function () {
- return this.str
-}
-
-/**
- * A token update function is used when updating or optionally
- * when cloning a token.
- *
- * @callback lunr.Token~updateFunction
- * @param {string} str - The string representation of the token.
- * @param {Object} metadata - All metadata associated with this token.
- */
-
-/**
- * Applies the given function to the wrapped string token.
- *
- * @example
- * token.update(function (str, metadata) {
- * return str.toUpperCase()
- * })
- *
- * @param {lunr.Token~updateFunction} fn - A function to apply to the token string.
- * @returns {lunr.Token}
- */
-lunr.Token.prototype.update = function (fn) {
- this.str = fn(this.str, this.metadata)
- return this
-}
-
-/**
- * Creates a clone of this token. Optionally a function can be
- * applied to the cloned token.
- *
- * @param {lunr.Token~updateFunction} [fn] - An optional function to apply to the cloned token.
- * @returns {lunr.Token}
- */
-lunr.Token.prototype.clone = function (fn) {
- fn = fn || function (s) { return s }
- return new lunr.Token (fn(this.str, this.metadata), this.metadata)
-}
-/*!
- * lunr.tokenizer
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * A function for splitting a string into tokens ready to be inserted into
- * the search index. Uses `lunr.tokenizer.separator` to split strings, change
- * the value of this property to change how strings are split into tokens.
- *
- * This tokenizer will convert its parameter to a string by calling `toString` and
- * then will split this string on the character in `lunr.tokenizer.separator`.
- * Arrays will have their elements converted to strings and wrapped in a lunr.Token.
- *
- * Optional metadata can be passed to the tokenizer, this metadata will be cloned and
- * added as metadata to every token that is created from the object to be tokenized.
- *
- * @static
- * @param {?(string|object|object[])} obj - The object to convert into tokens
- * @param {?object} metadata - Optional metadata to associate with every token
- * @returns {lunr.Token[]}
- * @see {@link lunr.Pipeline}
- */
-lunr.tokenizer = function (obj, metadata) {
- if (obj == null || obj == undefined) {
- return []
- }
-
- if (Array.isArray(obj)) {
- return obj.map(function (t) {
- return new lunr.Token(
- lunr.utils.asString(t).toLowerCase(),
- lunr.utils.clone(metadata)
- )
- })
- }
-
- var str = obj.toString().trim().toLowerCase(),
- len = str.length,
- tokens = []
-
- for (var sliceEnd = 0, sliceStart = 0; sliceEnd <= len; sliceEnd++) {
- var char = str.charAt(sliceEnd),
- sliceLength = sliceEnd - sliceStart
-
- if ((char.match(lunr.tokenizer.separator) || sliceEnd == len)) {
-
- if (sliceLength > 0) {
- var tokenMetadata = lunr.utils.clone(metadata) || {}
- tokenMetadata["position"] = [sliceStart, sliceLength]
- tokenMetadata["index"] = tokens.length
-
- tokens.push(
- new lunr.Token (
- str.slice(sliceStart, sliceEnd),
- tokenMetadata
- )
- )
- }
-
- sliceStart = sliceEnd + 1
- }
-
- }
-
- return tokens
-}
-
-/**
- * The separator used to split a string into tokens. Override this property to change the behaviour of
- * `lunr.tokenizer` behaviour when tokenizing strings. By default this splits on whitespace and hyphens.
- *
- * @static
- * @see lunr.tokenizer
- */
-lunr.tokenizer.separator = /[\s\-]+/
-/*!
- * lunr.Pipeline
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * lunr.Pipelines maintain an ordered list of functions to be applied to all
- * tokens in documents entering the search index and queries being ran against
- * the index.
- *
- * An instance of lunr.Index created with the lunr shortcut will contain a
- * pipeline with a stop word filter and an English language stemmer. Extra
- * functions can be added before or after either of these functions or these
- * default functions can be removed.
- *
- * When run the pipeline will call each function in turn, passing a token, the
- * index of that token in the original list of all tokens and finally a list of
- * all the original tokens.
- *
- * The output of functions in the pipeline will be passed to the next function
- * in the pipeline. To exclude a token from entering the index the function
- * should return undefined, the rest of the pipeline will not be called with
- * this token.
- *
- * For serialisation of pipelines to work, all functions used in an instance of
- * a pipeline should be registered with lunr.Pipeline. Registered functions can
- * then be loaded. If trying to load a serialised pipeline that uses functions
- * that are not registered an error will be thrown.
- *
- * If not planning on serialising the pipeline then registering pipeline functions
- * is not necessary.
- *
- * @constructor
- */
-lunr.Pipeline = function () {
- this._stack = []
-}
-
-lunr.Pipeline.registeredFunctions = Object.create(null)
-
-/**
- * A pipeline function maps lunr.Token to lunr.Token. A lunr.Token contains the token
- * string as well as all known metadata. A pipeline function can mutate the token string
- * or mutate (or add) metadata for a given token.
- *
- * A pipeline function can indicate that the passed token should be discarded by returning
- * null. This token will not be passed to any downstream pipeline functions and will not be
- * added to the index.
- *
- * Multiple tokens can be returned by returning an array of tokens. Each token will be passed
- * to any downstream pipeline functions and all will returned tokens will be added to the index.
- *
- * Any number of pipeline functions may be chained together using a lunr.Pipeline.
- *
- * @interface lunr.PipelineFunction
- * @param {lunr.Token} token - A token from the document being processed.
- * @param {number} i - The index of this token in the complete list of tokens for this document/field.
- * @param {lunr.Token[]} tokens - All tokens for this document/field.
- * @returns {(?lunr.Token|lunr.Token[])}
- */
-
-/**
- * Register a function with the pipeline.
- *
- * Functions that are used in the pipeline should be registered if the pipeline
- * needs to be serialised, or a serialised pipeline needs to be loaded.
- *
- * Registering a function does not add it to a pipeline, functions must still be
- * added to instances of the pipeline for them to be used when running a pipeline.
- *
- * @param {lunr.PipelineFunction} fn - The function to check for.
- * @param {String} label - The label to register this function with
- */
-lunr.Pipeline.registerFunction = function (fn, label) {
- if (label in this.registeredFunctions) {
- lunr.utils.warn('Overwriting existing registered function: ' + label)
- }
-
- fn.label = label
- lunr.Pipeline.registeredFunctions[fn.label] = fn
-}
-
-/**
- * Warns if the function is not registered as a Pipeline function.
- *
- * @param {lunr.PipelineFunction} fn - The function to check for.
- * @private
- */
-lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
- var isRegistered = fn.label && (fn.label in this.registeredFunctions)
-
- if (!isRegistered) {
- lunr.utils.warn('Function is not registered with pipeline. This may cause problems when serialising the index.\n', fn)
- }
-}
-
-/**
- * Loads a previously serialised pipeline.
- *
- * All functions to be loaded must already be registered with lunr.Pipeline.
- * If any function from the serialised data has not been registered then an
- * error will be thrown.
- *
- * @param {Object} serialised - The serialised pipeline to load.
- * @returns {lunr.Pipeline}
- */
-lunr.Pipeline.load = function (serialised) {
- var pipeline = new lunr.Pipeline
-
- serialised.forEach(function (fnName) {
- var fn = lunr.Pipeline.registeredFunctions[fnName]
-
- if (fn) {
- pipeline.add(fn)
- } else {
- throw new Error('Cannot load unregistered function: ' + fnName)
- }
- })
-
- return pipeline
-}
-
-/**
- * Adds new functions to the end of the pipeline.
- *
- * Logs a warning if the function has not been registered.
- *
- * @param {lunr.PipelineFunction[]} functions - Any number of functions to add to the pipeline.
- */
-lunr.Pipeline.prototype.add = function () {
- var fns = Array.prototype.slice.call(arguments)
-
- fns.forEach(function (fn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(fn)
- this._stack.push(fn)
- }, this)
-}
-
-/**
- * Adds a single function after a function that already exists in the
- * pipeline.
- *
- * Logs a warning if the function has not been registered.
- *
- * @param {lunr.PipelineFunction} existingFn - A function that already exists in the pipeline.
- * @param {lunr.PipelineFunction} newFn - The new function to add to the pipeline.
- */
-lunr.Pipeline.prototype.after = function (existingFn, newFn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
-
- var pos = this._stack.indexOf(existingFn)
- if (pos == -1) {
- throw new Error('Cannot find existingFn')
- }
-
- pos = pos + 1
- this._stack.splice(pos, 0, newFn)
-}
-
-/**
- * Adds a single function before a function that already exists in the
- * pipeline.
- *
- * Logs a warning if the function has not been registered.
- *
- * @param {lunr.PipelineFunction} existingFn - A function that already exists in the pipeline.
- * @param {lunr.PipelineFunction} newFn - The new function to add to the pipeline.
- */
-lunr.Pipeline.prototype.before = function (existingFn, newFn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
-
- var pos = this._stack.indexOf(existingFn)
- if (pos == -1) {
- throw new Error('Cannot find existingFn')
- }
-
- this._stack.splice(pos, 0, newFn)
-}
-
-/**
- * Removes a function from the pipeline.
- *
- * @param {lunr.PipelineFunction} fn The function to remove from the pipeline.
- */
-lunr.Pipeline.prototype.remove = function (fn) {
- var pos = this._stack.indexOf(fn)
- if (pos == -1) {
- return
- }
-
- this._stack.splice(pos, 1)
-}
-
-/**
- * Runs the current list of functions that make up the pipeline against the
- * passed tokens.
- *
- * @param {Array} tokens The tokens to run through the pipeline.
- * @returns {Array}
- */
-lunr.Pipeline.prototype.run = function (tokens) {
- var stackLength = this._stack.length
-
- for (var i = 0; i < stackLength; i++) {
- var fn = this._stack[i]
- var memo = []
-
- for (var j = 0; j < tokens.length; j++) {
- var result = fn(tokens[j], j, tokens)
-
- if (result === void 0 || result === '') continue
-
- if (result instanceof Array) {
- for (var k = 0; k < result.length; k++) {
- memo.push(result[k])
- }
- } else {
- memo.push(result)
- }
- }
-
- tokens = memo
- }
-
- return tokens
-}
-
-/**
- * Convenience method for passing a string through a pipeline and getting
- * strings out. This method takes care of wrapping the passed string in a
- * token and mapping the resulting tokens back to strings.
- *
- * @param {string} str - The string to pass through the pipeline.
- * @param {?object} metadata - Optional metadata to associate with the token
- * passed to the pipeline.
- * @returns {string[]}
- */
-lunr.Pipeline.prototype.runString = function (str, metadata) {
- var token = new lunr.Token (str, metadata)
-
- return this.run([token]).map(function (t) {
- return t.toString()
- })
-}
-
-/**
- * Resets the pipeline by removing any existing processors.
- *
- */
-lunr.Pipeline.prototype.reset = function () {
- this._stack = []
-}
-
-/**
- * Returns a representation of the pipeline ready for serialisation.
- *
- * Logs a warning if the function has not been registered.
- *
- * @returns {Array}
- */
-lunr.Pipeline.prototype.toJSON = function () {
- return this._stack.map(function (fn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(fn)
-
- return fn.label
- })
-}
-/*!
- * lunr.Vector
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * A vector is used to construct the vector space of documents and queries. These
- * vectors support operations to determine the similarity between two documents or
- * a document and a query.
- *
- * Normally no parameters are required for initializing a vector, but in the case of
- * loading a previously dumped vector the raw elements can be provided to the constructor.
- *
- * For performance reasons vectors are implemented with a flat array, where an elements
- * index is immediately followed by its value. E.g. [index, value, index, value]. This
- * allows the underlying array to be as sparse as possible and still offer decent
- * performance when being used for vector calculations.
- *
- * @constructor
- * @param {Number[]} [elements] - The flat list of element index and element value pairs.
- */
-lunr.Vector = function (elements) {
- this._magnitude = 0
- this.elements = elements || []
-}
-
-
-/**
- * Calculates the position within the vector to insert a given index.
- *
- * This is used internally by insert and upsert. If there are duplicate indexes then
- * the position is returned as if the value for that index were to be updated, but it
- * is the callers responsibility to check whether there is a duplicate at that index
- *
- * @param {Number} insertIdx - The index at which the element should be inserted.
- * @returns {Number}
- */
-lunr.Vector.prototype.positionForIndex = function (index) {
- // For an empty vector the tuple can be inserted at the beginning
- if (this.elements.length == 0) {
- return 0
- }
-
- var start = 0,
- end = this.elements.length / 2,
- sliceLength = end - start,
- pivotPoint = Math.floor(sliceLength / 2),
- pivotIndex = this.elements[pivotPoint * 2]
-
- while (sliceLength > 1) {
- if (pivotIndex < index) {
- start = pivotPoint
- }
-
- if (pivotIndex > index) {
- end = pivotPoint
- }
-
- if (pivotIndex == index) {
- break
- }
-
- sliceLength = end - start
- pivotPoint = start + Math.floor(sliceLength / 2)
- pivotIndex = this.elements[pivotPoint * 2]
- }
-
- if (pivotIndex == index) {
- return pivotPoint * 2
- }
-
- if (pivotIndex > index) {
- return pivotPoint * 2
- }
-
- if (pivotIndex < index) {
- return (pivotPoint + 1) * 2
- }
-}
-
-/**
- * Inserts an element at an index within the vector.
- *
- * Does not allow duplicates, will throw an error if there is already an entry
- * for this index.
- *
- * @param {Number} insertIdx - The index at which the element should be inserted.
- * @param {Number} val - The value to be inserted into the vector.
- */
-lunr.Vector.prototype.insert = function (insertIdx, val) {
- this.upsert(insertIdx, val, function () {
- throw "duplicate index"
- })
-}
-
-/**
- * Inserts or updates an existing index within the vector.
- *
- * @param {Number} insertIdx - The index at which the element should be inserted.
- * @param {Number} val - The value to be inserted into the vector.
- * @param {function} fn - A function that is called for updates, the existing value and the
- * requested value are passed as arguments
- */
-lunr.Vector.prototype.upsert = function (insertIdx, val, fn) {
- this._magnitude = 0
- var position = this.positionForIndex(insertIdx)
-
- if (this.elements[position] == insertIdx) {
- this.elements[position + 1] = fn(this.elements[position + 1], val)
- } else {
- this.elements.splice(position, 0, insertIdx, val)
- }
-}
-
-/**
- * Calculates the magnitude of this vector.
- *
- * @returns {Number}
- */
-lunr.Vector.prototype.magnitude = function () {
- if (this._magnitude) return this._magnitude
-
- var sumOfSquares = 0,
- elementsLength = this.elements.length
-
- for (var i = 1; i < elementsLength; i += 2) {
- var val = this.elements[i]
- sumOfSquares += val * val
- }
-
- return this._magnitude = Math.sqrt(sumOfSquares)
-}
-
-/**
- * Calculates the dot product of this vector and another vector.
- *
- * @param {lunr.Vector} otherVector - The vector to compute the dot product with.
- * @returns {Number}
- */
-lunr.Vector.prototype.dot = function (otherVector) {
- var dotProduct = 0,
- a = this.elements, b = otherVector.elements,
- aLen = a.length, bLen = b.length,
- aVal = 0, bVal = 0,
- i = 0, j = 0
-
- while (i < aLen && j < bLen) {
- aVal = a[i], bVal = b[j]
- if (aVal < bVal) {
- i += 2
- } else if (aVal > bVal) {
- j += 2
- } else if (aVal == bVal) {
- dotProduct += a[i + 1] * b[j + 1]
- i += 2
- j += 2
- }
- }
-
- return dotProduct
-}
-
-/**
- * Calculates the similarity between this vector and another vector.
- *
- * @param {lunr.Vector} otherVector - The other vector to calculate the
- * similarity with.
- * @returns {Number}
- */
-lunr.Vector.prototype.similarity = function (otherVector) {
- return this.dot(otherVector) / this.magnitude() || 0
-}
-
-/**
- * Converts the vector to an array of the elements within the vector.
- *
- * @returns {Number[]}
- */
-lunr.Vector.prototype.toArray = function () {
- var output = new Array (this.elements.length / 2)
-
- for (var i = 1, j = 0; i < this.elements.length; i += 2, j++) {
- output[j] = this.elements[i]
- }
-
- return output
-}
-
-/**
- * A JSON serializable representation of the vector.
- *
- * @returns {Number[]}
- */
-lunr.Vector.prototype.toJSON = function () {
- return this.elements
-}
-/* eslint-disable */
-/*!
- * lunr.stemmer
- * Copyright (C) 2018 Oliver Nightingale
- * Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
- */
-
-/**
- * lunr.stemmer is an english language stemmer, this is a JavaScript
- * implementation of the PorterStemmer taken from http://tartarus.org/~martin
- *
- * @static
- * @implements {lunr.PipelineFunction}
- * @param {lunr.Token} token - The string to stem
- * @returns {lunr.Token}
- * @see {@link lunr.Pipeline}
- * @function
- */
-lunr.stemmer = (function(){
- var step2list = {
- "ational" : "ate",
- "tional" : "tion",
- "enci" : "ence",
- "anci" : "ance",
- "izer" : "ize",
- "bli" : "ble",
- "alli" : "al",
- "entli" : "ent",
- "eli" : "e",
- "ousli" : "ous",
- "ization" : "ize",
- "ation" : "ate",
- "ator" : "ate",
- "alism" : "al",
- "iveness" : "ive",
- "fulness" : "ful",
- "ousness" : "ous",
- "aliti" : "al",
- "iviti" : "ive",
- "biliti" : "ble",
- "logi" : "log"
- },
-
- step3list = {
- "icate" : "ic",
- "ative" : "",
- "alize" : "al",
- "iciti" : "ic",
- "ical" : "ic",
- "ful" : "",
- "ness" : ""
- },
-
- c = "[^aeiou]", // consonant
- v = "[aeiouy]", // vowel
- C = c + "[^aeiouy]*", // consonant sequence
- V = v + "[aeiou]*", // vowel sequence
-
- mgr0 = "^(" + C + ")?" + V + C, // [C]VC... is m>0
- meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$", // [C]VC[V] is m=1
- mgr1 = "^(" + C + ")?" + V + C + V + C, // [C]VCVC... is m>1
- s_v = "^(" + C + ")?" + v; // vowel in stem
-
- var re_mgr0 = new RegExp(mgr0);
- var re_mgr1 = new RegExp(mgr1);
- var re_meq1 = new RegExp(meq1);
- var re_s_v = new RegExp(s_v);
-
- var re_1a = /^(.+?)(ss|i)es$/;
- var re2_1a = /^(.+?)([^s])s$/;
- var re_1b = /^(.+?)eed$/;
- var re2_1b = /^(.+?)(ed|ing)$/;
- var re_1b_2 = /.$/;
- var re2_1b_2 = /(at|bl|iz)$/;
- var re3_1b_2 = new RegExp("([^aeiouylsz])\\1$");
- var re4_1b_2 = new RegExp("^" + C + v + "[^aeiouwxy]$");
-
- var re_1c = /^(.+?[^aeiou])y$/;
- var re_2 = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
-
- var re_3 = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
-
- var re_4 = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
- var re2_4 = /^(.+?)(s|t)(ion)$/;
-
- var re_5 = /^(.+?)e$/;
- var re_5_1 = /ll$/;
- var re3_5 = new RegExp("^" + C + v + "[^aeiouwxy]$");
-
- var porterStemmer = function porterStemmer(w) {
- var stem,
- suffix,
- firstch,
- re,
- re2,
- re3,
- re4;
-
- if (w.length < 3) { return w; }
-
- firstch = w.substr(0,1);
- if (firstch == "y") {
- w = firstch.toUpperCase() + w.substr(1);
- }
-
- // Step 1a
- re = re_1a
- re2 = re2_1a;
-
- if (re.test(w)) { w = w.replace(re,"$1$2"); }
- else if (re2.test(w)) { w = w.replace(re2,"$1$2"); }
-
- // Step 1b
- re = re_1b;
- re2 = re2_1b;
- if (re.test(w)) {
- var fp = re.exec(w);
- re = re_mgr0;
- if (re.test(fp[1])) {
- re = re_1b_2;
- w = w.replace(re,"");
- }
- } else if (re2.test(w)) {
- var fp = re2.exec(w);
- stem = fp[1];
- re2 = re_s_v;
- if (re2.test(stem)) {
- w = stem;
- re2 = re2_1b_2;
- re3 = re3_1b_2;
- re4 = re4_1b_2;
- if (re2.test(w)) { w = w + "e"; }
- else if (re3.test(w)) { re = re_1b_2; w = w.replace(re,""); }
- else if (re4.test(w)) { w = w + "e"; }
- }
- }
-
- // Step 1c - replace suffix y or Y by i if preceded by a non-vowel which is not the first letter of the word (so cry -> cri, by -> by, say -> say)
- re = re_1c;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- w = stem + "i";
- }
-
- // Step 2
- re = re_2;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- suffix = fp[2];
- re = re_mgr0;
- if (re.test(stem)) {
- w = stem + step2list[suffix];
- }
- }
-
- // Step 3
- re = re_3;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- suffix = fp[2];
- re = re_mgr0;
- if (re.test(stem)) {
- w = stem + step3list[suffix];
- }
- }
-
- // Step 4
- re = re_4;
- re2 = re2_4;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- re = re_mgr1;
- if (re.test(stem)) {
- w = stem;
- }
- } else if (re2.test(w)) {
- var fp = re2.exec(w);
- stem = fp[1] + fp[2];
- re2 = re_mgr1;
- if (re2.test(stem)) {
- w = stem;
- }
- }
-
- // Step 5
- re = re_5;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- re = re_mgr1;
- re2 = re_meq1;
- re3 = re3_5;
- if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) {
- w = stem;
- }
- }
-
- re = re_5_1;
- re2 = re_mgr1;
- if (re.test(w) && re2.test(w)) {
- re = re_1b_2;
- w = w.replace(re,"");
- }
-
- // and turn initial Y back to y
-
- if (firstch == "y") {
- w = firstch.toLowerCase() + w.substr(1);
- }
-
- return w;
- };
-
- return function (token) {
- return token.update(porterStemmer);
- }
-})();
-
-lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
-/*!
- * lunr.stopWordFilter
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * lunr.generateStopWordFilter builds a stopWordFilter function from the provided
- * list of stop words.
- *
- * The built in lunr.stopWordFilter is built using this generator and can be used
- * to generate custom stopWordFilters for applications or non English languages.
- *
- * @function
- * @param {Array} token The token to pass through the filter
- * @returns {lunr.PipelineFunction}
- * @see lunr.Pipeline
- * @see lunr.stopWordFilter
- */
-lunr.generateStopWordFilter = function (stopWords) {
- var words = stopWords.reduce(function (memo, stopWord) {
- memo[stopWord] = stopWord
- return memo
- }, {})
-
- return function (token) {
- if (token && words[token.toString()] !== token.toString()) return token
- }
-}
-
-/**
- * lunr.stopWordFilter is an English language stop word list filter, any words
- * contained in the list will not be passed through the filter.
- *
- * This is intended to be used in the Pipeline. If the token does not pass the
- * filter then undefined will be returned.
- *
- * @function
- * @implements {lunr.PipelineFunction}
- * @params {lunr.Token} token - A token to check for being a stop word.
- * @returns {lunr.Token}
- * @see {@link lunr.Pipeline}
- */
-lunr.stopWordFilter = lunr.generateStopWordFilter([
- 'a',
- 'able',
- 'about',
- 'across',
- 'after',
- 'all',
- 'almost',
- 'also',
- 'am',
- 'among',
- 'an',
- 'and',
- 'any',
- 'are',
- 'as',
- 'at',
- 'be',
- 'because',
- 'been',
- 'but',
- 'by',
- 'can',
- 'cannot',
- 'could',
- 'dear',
- 'did',
- 'do',
- 'does',
- 'either',
- 'else',
- 'ever',
- 'every',
- 'for',
- 'from',
- 'get',
- 'got',
- 'had',
- 'has',
- 'have',
- 'he',
- 'her',
- 'hers',
- 'him',
- 'his',
- 'how',
- 'however',
- 'i',
- 'if',
- 'in',
- 'into',
- 'is',
- 'it',
- 'its',
- 'just',
- 'least',
- 'let',
- 'like',
- 'likely',
- 'may',
- 'me',
- 'might',
- 'most',
- 'must',
- 'my',
- 'neither',
- 'no',
- 'nor',
- 'not',
- 'of',
- 'off',
- 'often',
- 'on',
- 'only',
- 'or',
- 'other',
- 'our',
- 'own',
- 'rather',
- 'said',
- 'say',
- 'says',
- 'she',
- 'should',
- 'since',
- 'so',
- 'some',
- 'than',
- 'that',
- 'the',
- 'their',
- 'them',
- 'then',
- 'there',
- 'these',
- 'they',
- 'this',
- 'tis',
- 'to',
- 'too',
- 'twas',
- 'us',
- 'wants',
- 'was',
- 'we',
- 'were',
- 'what',
- 'when',
- 'where',
- 'which',
- 'while',
- 'who',
- 'whom',
- 'why',
- 'will',
- 'with',
- 'would',
- 'yet',
- 'you',
- 'your'
-])
-
-lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
-/*!
- * lunr.trimmer
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * lunr.trimmer is a pipeline function for trimming non word
- * characters from the beginning and end of tokens before they
- * enter the index.
- *
- * This implementation may not work correctly for non latin
- * characters and should either be removed or adapted for use
- * with languages with non-latin characters.
- *
- * @static
- * @implements {lunr.PipelineFunction}
- * @param {lunr.Token} token The token to pass through the filter
- * @returns {lunr.Token}
- * @see lunr.Pipeline
- */
-lunr.trimmer = function (token) {
- return token.update(function (s) {
- return s.replace(/^\W+/, '').replace(/\W+$/, '')
- })
-}
-
-lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
-/*!
- * lunr.TokenSet
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * A token set is used to store the unique list of all tokens
- * within an index. Token sets are also used to represent an
- * incoming query to the index, this query token set and index
- * token set are then intersected to find which tokens to look
- * up in the inverted index.
- *
- * A token set can hold multiple tokens, as in the case of the
- * index token set, or it can hold a single token as in the
- * case of a simple query token set.
- *
- * Additionally token sets are used to perform wildcard matching.
- * Leading, contained and trailing wildcards are supported, and
- * from this edit distance matching can also be provided.
- *
- * Token sets are implemented as a minimal finite state automata,
- * where both common prefixes and suffixes are shared between tokens.
- * This helps to reduce the space used for storing the token set.
- *
- * @constructor
- */
-lunr.TokenSet = function () {
- this.final = false
- this.edges = {}
- this.id = lunr.TokenSet._nextId
- lunr.TokenSet._nextId += 1
-}
-
-/**
- * Keeps track of the next, auto increment, identifier to assign
- * to a new tokenSet.
- *
- * TokenSets require a unique identifier to be correctly minimised.
- *
- * @private
- */
-lunr.TokenSet._nextId = 1
-
-/**
- * Creates a TokenSet instance from the given sorted array of words.
- *
- * @param {String[]} arr - A sorted array of strings to create the set from.
- * @returns {lunr.TokenSet}
- * @throws Will throw an error if the input array is not sorted.
- */
-lunr.TokenSet.fromArray = function (arr) {
- var builder = new lunr.TokenSet.Builder
-
- for (var i = 0, len = arr.length; i < len; i++) {
- builder.insert(arr[i])
- }
-
- builder.finish()
- return builder.root
-}
-
-/**
- * Creates a token set from a query clause.
- *
- * @private
- * @param {Object} clause - A single clause from lunr.Query.
- * @param {string} clause.term - The query clause term.
- * @param {number} [clause.editDistance] - The optional edit distance for the term.
- * @returns {lunr.TokenSet}
- */
-lunr.TokenSet.fromClause = function (clause) {
- if ('editDistance' in clause) {
- return lunr.TokenSet.fromFuzzyString(clause.term, clause.editDistance)
- } else {
- return lunr.TokenSet.fromString(clause.term)
- }
-}
-
-/**
- * Creates a token set representing a single string with a specified
- * edit distance.
- *
- * Insertions, deletions, substitutions and transpositions are each
- * treated as an edit distance of 1.
- *
- * Increasing the allowed edit distance will have a dramatic impact
- * on the performance of both creating and intersecting these TokenSets.
- * It is advised to keep the edit distance less than 3.
- *
- * @param {string} str - The string to create the token set from.
- * @param {number} editDistance - The allowed edit distance to match.
- * @returns {lunr.Vector}
- */
-lunr.TokenSet.fromFuzzyString = function (str, editDistance) {
- var root = new lunr.TokenSet
-
- var stack = [{
- node: root,
- editsRemaining: editDistance,
- str: str
- }]
-
- while (stack.length) {
- var frame = stack.pop()
-
- // no edit
- if (frame.str.length > 0) {
- var char = frame.str.charAt(0),
- noEditNode
-
- if (char in frame.node.edges) {
- noEditNode = frame.node.edges[char]
- } else {
- noEditNode = new lunr.TokenSet
- frame.node.edges[char] = noEditNode
- }
-
- if (frame.str.length == 1) {
- noEditNode.final = true
- } else {
- stack.push({
- node: noEditNode,
- editsRemaining: frame.editsRemaining,
- str: frame.str.slice(1)
- })
- }
- }
-
- // deletion
- // can only do a deletion if we have enough edits remaining
- // and if there are characters left to delete in the string
- if (frame.editsRemaining > 0 && frame.str.length > 1) {
- var char = frame.str.charAt(1),
- deletionNode
-
- if (char in frame.node.edges) {
- deletionNode = frame.node.edges[char]
- } else {
- deletionNode = new lunr.TokenSet
- frame.node.edges[char] = deletionNode
- }
-
- if (frame.str.length <= 2) {
- deletionNode.final = true
- } else {
- stack.push({
- node: deletionNode,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str.slice(2)
- })
- }
- }
-
- // deletion
- // just removing the last character from the str
- if (frame.editsRemaining > 0 && frame.str.length == 1) {
- frame.node.final = true
- }
-
- // substitution
- // can only do a substitution if we have enough edits remaining
- // and if there are characters left to substitute
- if (frame.editsRemaining > 0 && frame.str.length >= 1) {
- if ("*" in frame.node.edges) {
- var substitutionNode = frame.node.edges["*"]
- } else {
- var substitutionNode = new lunr.TokenSet
- frame.node.edges["*"] = substitutionNode
- }
-
- if (frame.str.length == 1) {
- substitutionNode.final = true
- } else {
- stack.push({
- node: substitutionNode,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str.slice(1)
- })
- }
- }
-
- // insertion
- // can only do insertion if there are edits remaining
- if (frame.editsRemaining > 0) {
- if ("*" in frame.node.edges) {
- var insertionNode = frame.node.edges["*"]
- } else {
- var insertionNode = new lunr.TokenSet
- frame.node.edges["*"] = insertionNode
- }
-
- if (frame.str.length == 0) {
- insertionNode.final = true
- } else {
- stack.push({
- node: insertionNode,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str
- })
- }
- }
-
- // transposition
- // can only do a transposition if there are edits remaining
- // and there are enough characters to transpose
- if (frame.editsRemaining > 0 && frame.str.length > 1) {
- var charA = frame.str.charAt(0),
- charB = frame.str.charAt(1),
- transposeNode
-
- if (charB in frame.node.edges) {
- transposeNode = frame.node.edges[charB]
- } else {
- transposeNode = new lunr.TokenSet
- frame.node.edges[charB] = transposeNode
- }
-
- if (frame.str.length == 1) {
- transposeNode.final = true
- } else {
- stack.push({
- node: transposeNode,
- editsRemaining: frame.editsRemaining - 1,
- str: charA + frame.str.slice(2)
- })
- }
- }
- }
-
- return root
-}
-
-/**
- * Creates a TokenSet from a string.
- *
- * The string may contain one or more wildcard characters (*)
- * that will allow wildcard matching when intersecting with
- * another TokenSet.
- *
- * @param {string} str - The string to create a TokenSet from.
- * @returns {lunr.TokenSet}
- */
-lunr.TokenSet.fromString = function (str) {
- var node = new lunr.TokenSet,
- root = node
-
- /*
- * Iterates through all characters within the passed string
- * appending a node for each character.
- *
- * When a wildcard character is found then a self
- * referencing edge is introduced to continually match
- * any number of any characters.
- */
- for (var i = 0, len = str.length; i < len; i++) {
- var char = str[i],
- final = (i == len - 1)
-
- if (char == "*") {
- node.edges[char] = node
- node.final = final
-
- } else {
- var next = new lunr.TokenSet
- next.final = final
-
- node.edges[char] = next
- node = next
- }
- }
-
- return root
-}
-
-/**
- * Converts this TokenSet into an array of strings
- * contained within the TokenSet.
- *
- * @returns {string[]}
- */
-lunr.TokenSet.prototype.toArray = function () {
- var words = []
-
- var stack = [{
- prefix: "",
- node: this
- }]
-
- while (stack.length) {
- var frame = stack.pop(),
- edges = Object.keys(frame.node.edges),
- len = edges.length
-
- if (frame.node.final) {
- /* In Safari, at this point the prefix is sometimes corrupted, see:
- * https://github.com/olivernn/lunr.js/issues/279 Calling any
- * String.prototype method forces Safari to "cast" this string to what
- * it's supposed to be, fixing the bug. */
- frame.prefix.charAt(0)
- words.push(frame.prefix)
- }
-
- for (var i = 0; i < len; i++) {
- var edge = edges[i]
-
- stack.push({
- prefix: frame.prefix.concat(edge),
- node: frame.node.edges[edge]
- })
- }
- }
-
- return words
-}
-
-/**
- * Generates a string representation of a TokenSet.
- *
- * This is intended to allow TokenSets to be used as keys
- * in objects, largely to aid the construction and minimisation
- * of a TokenSet. As such it is not designed to be a human
- * friendly representation of the TokenSet.
- *
- * @returns {string}
- */
-lunr.TokenSet.prototype.toString = function () {
- // NOTE: Using Object.keys here as this.edges is very likely
- // to enter 'hash-mode' with many keys being added
- //
- // avoiding a for-in loop here as it leads to the function
- // being de-optimised (at least in V8). From some simple
- // benchmarks the performance is comparable, but allowing
- // V8 to optimize may mean easy performance wins in the future.
-
- if (this._str) {
- return this._str
- }
-
- var str = this.final ? '1' : '0',
- labels = Object.keys(this.edges).sort(),
- len = labels.length
-
- for (var i = 0; i < len; i++) {
- var label = labels[i],
- node = this.edges[label]
-
- str = str + label + node.id
- }
-
- return str
-}
-
-/**
- * Returns a new TokenSet that is the intersection of
- * this TokenSet and the passed TokenSet.
- *
- * This intersection will take into account any wildcards
- * contained within the TokenSet.
- *
- * @param {lunr.TokenSet} b - An other TokenSet to intersect with.
- * @returns {lunr.TokenSet}
- */
-lunr.TokenSet.prototype.intersect = function (b) {
- var output = new lunr.TokenSet,
- frame = undefined
-
- var stack = [{
- qNode: b,
- output: output,
- node: this
- }]
-
- while (stack.length) {
- frame = stack.pop()
-
- // NOTE: As with the #toString method, we are using
- // Object.keys and a for loop instead of a for-in loop
- // as both of these objects enter 'hash' mode, causing
- // the function to be de-optimised in V8
- var qEdges = Object.keys(frame.qNode.edges),
- qLen = qEdges.length,
- nEdges = Object.keys(frame.node.edges),
- nLen = nEdges.length
-
- for (var q = 0; q < qLen; q++) {
- var qEdge = qEdges[q]
-
- for (var n = 0; n < nLen; n++) {
- var nEdge = nEdges[n]
-
- if (nEdge == qEdge || qEdge == '*') {
- var node = frame.node.edges[nEdge],
- qNode = frame.qNode.edges[qEdge],
- final = node.final && qNode.final,
- next = undefined
-
- if (nEdge in frame.output.edges) {
- // an edge already exists for this character
- // no need to create a new node, just set the finality
- // bit unless this node is already final
- next = frame.output.edges[nEdge]
- next.final = next.final || final
-
- } else {
- // no edge exists yet, must create one
- // set the finality bit and insert it
- // into the output
- next = new lunr.TokenSet
- next.final = final
- frame.output.edges[nEdge] = next
- }
-
- stack.push({
- qNode: qNode,
- output: next,
- node: node
- })
- }
- }
- }
- }
-
- return output
-}
-lunr.TokenSet.Builder = function () {
- this.previousWord = ""
- this.root = new lunr.TokenSet
- this.uncheckedNodes = []
- this.minimizedNodes = {}
-}
-
-lunr.TokenSet.Builder.prototype.insert = function (word) {
- var node,
- commonPrefix = 0
-
- if (word < this.previousWord) {
- throw new Error ("Out of order word insertion")
- }
-
- for (var i = 0; i < word.length && i < this.previousWord.length; i++) {
- if (word[i] != this.previousWord[i]) break
- commonPrefix++
- }
-
- this.minimize(commonPrefix)
-
- if (this.uncheckedNodes.length == 0) {
- node = this.root
- } else {
- node = this.uncheckedNodes[this.uncheckedNodes.length - 1].child
- }
-
- for (var i = commonPrefix; i < word.length; i++) {
- var nextNode = new lunr.TokenSet,
- char = word[i]
-
- node.edges[char] = nextNode
-
- this.uncheckedNodes.push({
- parent: node,
- char: char,
- child: nextNode
- })
-
- node = nextNode
- }
-
- node.final = true
- this.previousWord = word
-}
-
-lunr.TokenSet.Builder.prototype.finish = function () {
- this.minimize(0)
-}
-
-lunr.TokenSet.Builder.prototype.minimize = function (downTo) {
- for (var i = this.uncheckedNodes.length - 1; i >= downTo; i--) {
- var node = this.uncheckedNodes[i],
- childKey = node.child.toString()
-
- if (childKey in this.minimizedNodes) {
- node.parent.edges[node.char] = this.minimizedNodes[childKey]
- } else {
- // Cache the key for this node since
- // we know it can't change anymore
- node.child._str = childKey
-
- this.minimizedNodes[childKey] = node.child
- }
-
- this.uncheckedNodes.pop()
- }
-}
-/*!
- * lunr.Index
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * An index contains the built index of all documents and provides a query interface
- * to the index.
- *
- * Usually instances of lunr.Index will not be created using this constructor, instead
- * lunr.Builder should be used to construct new indexes, or lunr.Index.load should be
- * used to load previously built and serialized indexes.
- *
- * @constructor
- * @param {Object} attrs - The attributes of the built search index.
- * @param {Object} attrs.invertedIndex - An index of term/field to document reference.
- * @param {Object<string, lunr.Vector>} attrs.fieldVectors - Field vectors
- * @param {lunr.TokenSet} attrs.tokenSet - An set of all corpus tokens.
- * @param {string[]} attrs.fields - The names of indexed document fields.
- * @param {lunr.Pipeline} attrs.pipeline - The pipeline to use for search terms.
- */
-lunr.Index = function (attrs) {
- this.invertedIndex = attrs.invertedIndex
- this.fieldVectors = attrs.fieldVectors
- this.tokenSet = attrs.tokenSet
- this.fields = attrs.fields
- this.pipeline = attrs.pipeline
-}
-
-/**
- * A result contains details of a document matching a search query.
- * @typedef {Object} lunr.Index~Result
- * @property {string} ref - The reference of the document this result represents.
- * @property {number} score - A number between 0 and 1 representing how similar this document is to the query.
- * @property {lunr.MatchData} matchData - Contains metadata about this match including which term(s) caused the match.
- */
-
-/**
- * Although lunr provides the ability to create queries using lunr.Query, it also provides a simple
- * query language which itself is parsed into an instance of lunr.Query.
- *
- * For programmatically building queries it is advised to directly use lunr.Query, the query language
- * is best used for human entered text rather than program generated text.
- *
- * At its simplest queries can just be a single term, e.g. `hello`, multiple terms are also supported
- * and will be combined with OR, e.g `hello world` will match documents that contain either 'hello'
- * or 'world', though those that contain both will rank higher in the results.
- *
- * Wildcards can be included in terms to match one or more unspecified characters, these wildcards can
- * be inserted anywhere within the term, and more than one wildcard can exist in a single term. Adding
- * wildcards will increase the number of documents that will be found but can also have a negative
- * impact on query performance, especially with wildcards at the beginning of a term.
- *
- * Terms can be restricted to specific fields, e.g. `title:hello`, only documents with the term
- * hello in the title field will match this query. Using a field not present in the index will lead
- * to an error being thrown.
- *
- * Modifiers can also be added to terms, lunr supports edit distance and boost modifiers on terms. A term
- * boost will make documents matching that term score higher, e.g. `foo^5`. Edit distance is also supported
- * to provide fuzzy matching, e.g. 'hello~2' will match documents with hello with an edit distance of 2.
- * Avoid large values for edit distance to improve query performance.
- *
- * Each term also supports a presence modifier. By default a term's presence in document is optional, however
- * this can be changed to either required or prohibited. For a term's presence to be required in a document the
- * term should be prefixed with a '+', e.g. `+foo bar` is a search for documents that must contain 'foo' and
- * optionally contain 'bar'. Conversely a leading '-' sets the terms presence to prohibited, i.e. it must not
- * appear in a document, e.g. `-foo bar` is a search for documents that do not contain 'foo' but may contain 'bar'.
- *
- * To escape special characters the backslash character '\' can be used, this allows searches to include
- * characters that would normally be considered modifiers, e.g. `foo\~2` will search for a term "foo~2" instead
- * of attempting to apply a boost of 2 to the search term "foo".
- *
- * @typedef {string} lunr.Index~QueryString
- * @example <caption>Simple single term query</caption>
- * hello
- * @example <caption>Multiple term query</caption>
- * hello world
- * @example <caption>term scoped to a field</caption>
- * title:hello
- * @example <caption>term with a boost of 10</caption>
- * hello^10
- * @example <caption>term with an edit distance of 2</caption>
- * hello~2
- * @example <caption>terms with presence modifiers</caption>
- * -foo +bar baz
- */
-
-/**
- * Performs a search against the index using lunr query syntax.
- *
- * Results will be returned sorted by their score, the most relevant results
- * will be returned first. For details on how the score is calculated, please see
- * the {@link https://lunrjs.com/guides/searching.html#scoring|guide}.
- *
- * For more programmatic querying use lunr.Index#query.
- *
- * @param {lunr.Index~QueryString} queryString - A string containing a lunr query.
- * @throws {lunr.QueryParseError} If the passed query string cannot be parsed.
- * @returns {lunr.Index~Result[]}
- */
-lunr.Index.prototype.search = function (queryString) {
- return this.query(function (query) {
- var parser = new lunr.QueryParser(queryString, query)
- parser.parse()
- })
-}
-
-/**
- * A query builder callback provides a query object to be used to express
- * the query to perform on the index.
- *
- * @callback lunr.Index~queryBuilder
- * @param {lunr.Query} query - The query object to build up.
- * @this lunr.Query
- */
-
-/**
- * Performs a query against the index using the yielded lunr.Query object.
- *
- * If performing programmatic queries against the index, this method is preferred
- * over lunr.Index#search so as to avoid the additional query parsing overhead.
- *
- * A query object is yielded to the supplied function which should be used to
- * express the query to be run against the index.
- *
- * Note that although this function takes a callback parameter it is _not_ an
- * asynchronous operation, the callback is just yielded a query object to be
- * customized.
- *
- * @param {lunr.Index~queryBuilder} fn - A function that is used to build the query.
- * @returns {lunr.Index~Result[]}
- */
-lunr.Index.prototype.query = function (fn) {
- // for each query clause
- // * process terms
- // * expand terms from token set
- // * find matching documents and metadata
- // * get document vectors
- // * score documents
-
- var query = new lunr.Query(this.fields),
- matchingFields = Object.create(null),
- queryVectors = Object.create(null),
- termFieldCache = Object.create(null),
- requiredMatches = Object.create(null),
- prohibitedMatches = Object.create(null)
-
- /*
- * To support field level boosts a query vector is created per
- * field. An empty vector is eagerly created to support negated
- * queries.
- */
- for (var i = 0; i < this.fields.length; i++) {
- queryVectors[this.fields[i]] = new lunr.Vector
- }
-
- fn.call(query, query)
-
- for (var i = 0; i < query.clauses.length; i++) {
- /*
- * Unless the pipeline has been disabled for this term, which is
- * the case for terms with wildcards, we need to pass the clause
- * term through the search pipeline. A pipeline returns an array
- * of processed terms. Pipeline functions may expand the passed
- * term, which means we may end up performing multiple index lookups
- * for a single query term.
- */
- var clause = query.clauses[i],
- terms = null,
- clauseMatches = lunr.Set.complete
-
- if (clause.usePipeline) {
- terms = this.pipeline.runString(clause.term, {
- fields: clause.fields
- })
- } else {
- terms = [clause.term]
- }
-
- for (var m = 0; m < terms.length; m++) {
- var term = terms[m]
-
- /*
- * Each term returned from the pipeline needs to use the same query
- * clause object, e.g. the same boost and or edit distance. The
- * simplest way to do this is to re-use the clause object but mutate
- * its term property.
- */
- clause.term = term
-
- /*
- * From the term in the clause we create a token set which will then
- * be used to intersect the indexes token set to get a list of terms
- * to lookup in the inverted index
- */
- var termTokenSet = lunr.TokenSet.fromClause(clause),
- expandedTerms = this.tokenSet.intersect(termTokenSet).toArray()
-
- /*
- * If a term marked as required does not exist in the tokenSet it is
- * impossible for the search to return any matches. We set all the field
- * scoped required matches set to empty and stop examining any further
- * clauses.
- */
- if (expandedTerms.length === 0 && clause.presence === lunr.Query.presence.REQUIRED) {
- for (var k = 0; k < clause.fields.length; k++) {
- var field = clause.fields[k]
- requiredMatches[field] = lunr.Set.empty
- }
-
- break
- }
-
- for (var j = 0; j < expandedTerms.length; j++) {
- /*
- * For each term get the posting and termIndex, this is required for
- * building the query vector.
- */
- var expandedTerm = expandedTerms[j],
- posting = this.invertedIndex[expandedTerm],
- termIndex = posting._index
-
- for (var k = 0; k < clause.fields.length; k++) {
- /*
- * For each field that this query term is scoped by (by default
- * all fields are in scope) we need to get all the document refs
- * that have this term in that field.
- *
- * The posting is the entry in the invertedIndex for the matching
- * term from above.
- */
- var field = clause.fields[k],
- fieldPosting = posting[field],
- matchingDocumentRefs = Object.keys(fieldPosting),
- termField = expandedTerm + "/" + field,
- matchingDocumentsSet = new lunr.Set(matchingDocumentRefs)
-
- /*
- * if the presence of this term is required ensure that the matching
- * documents are added to the set of required matches for this clause.
- *
- */
- if (clause.presence == lunr.Query.presence.REQUIRED) {
- clauseMatches = clauseMatches.union(matchingDocumentsSet)
-
- if (requiredMatches[field] === undefined) {
- requiredMatches[field] = lunr.Set.complete
- }
- }
-
- /*
- * if the presence of this term is prohibited ensure that the matching
- * documents are added to the set of prohibited matches for this field,
- * creating that set if it does not yet exist.
- */
- if (clause.presence == lunr.Query.presence.PROHIBITED) {
- if (prohibitedMatches[field] === undefined) {
- prohibitedMatches[field] = lunr.Set.empty
- }
-
- prohibitedMatches[field] = prohibitedMatches[field].union(matchingDocumentsSet)
-
- /*
- * Prohibited matches should not be part of the query vector used for
- * similarity scoring and no metadata should be extracted so we continue
- * to the next field
- */
- continue
- }
-
- /*
- * The query field vector is populated using the termIndex found for
- * the term and a unit value with the appropriate boost applied.
- * Using upsert because there could already be an entry in the vector
- * for the term we are working with. In that case we just add the scores
- * together.
- */
- queryVectors[field].upsert(termIndex, clause.boost, function (a, b) { return a + b })
-
- /**
- * If we've already seen this term, field combo then we've already collected
- * the matching documents and metadata, no need to go through all that again
- */
- if (termFieldCache[termField]) {
- continue
- }
-
- for (var l = 0; l < matchingDocumentRefs.length; l++) {
- /*
- * All metadata for this term/field/document triple
- * are then extracted and collected into an instance
- * of lunr.MatchData ready to be returned in the query
- * results
- */
- var matchingDocumentRef = matchingDocumentRefs[l],
- matchingFieldRef = new lunr.FieldRef (matchingDocumentRef, field),
- metadata = fieldPosting[matchingDocumentRef],
- fieldMatch
-
- if ((fieldMatch = matchingFields[matchingFieldRef]) === undefined) {
- matchingFields[matchingFieldRef] = new lunr.MatchData (expandedTerm, field, metadata)
- } else {
- fieldMatch.add(expandedTerm, field, metadata)
- }
-
- }
-
- termFieldCache[termField] = true
- }
- }
- }
-
- /**
- * If the presence was required we need to update the requiredMatches field sets.
- * We do this after all fields for the term have collected their matches because
- * the clause terms presence is required in _any_ of the fields not _all_ of the
- * fields.
- */
- if (clause.presence === lunr.Query.presence.REQUIRED) {
- for (var k = 0; k < clause.fields.length; k++) {
- var field = clause.fields[k]
- requiredMatches[field] = requiredMatches[field].intersect(clauseMatches)
- }
- }
- }
-
- /**
- * Need to combine the field scoped required and prohibited
- * matching documents into a global set of required and prohibited
- * matches
- */
- var allRequiredMatches = lunr.Set.complete,
- allProhibitedMatches = lunr.Set.empty
-
- for (var i = 0; i < this.fields.length; i++) {
- var field = this.fields[i]
-
- if (requiredMatches[field]) {
- allRequiredMatches = allRequiredMatches.intersect(requiredMatches[field])
- }
-
- if (prohibitedMatches[field]) {
- allProhibitedMatches = allProhibitedMatches.union(prohibitedMatches[field])
- }
- }
-
- var matchingFieldRefs = Object.keys(matchingFields),
- results = [],
- matches = Object.create(null)
-
- /*
- * If the query is negated (contains only prohibited terms)
- * we need to get _all_ fieldRefs currently existing in the
- * index. This is only done when we know that the query is
- * entirely prohibited terms to avoid any cost of getting all
- * fieldRefs unnecessarily.
- *
- * Additionally, blank MatchData must be created to correctly
- * populate the results.
- */
- if (query.isNegated()) {
- matchingFieldRefs = Object.keys(this.fieldVectors)
-
- for (var i = 0; i < matchingFieldRefs.length; i++) {
- var matchingFieldRef = matchingFieldRefs[i]
- var fieldRef = lunr.FieldRef.fromString(matchingFieldRef)
- matchingFields[matchingFieldRef] = new lunr.MatchData
- }
- }
-
- for (var i = 0; i < matchingFieldRefs.length; i++) {
- /*
- * Currently we have document fields that match the query, but we
- * need to return documents. The matchData and scores are combined
- * from multiple fields belonging to the same document.
- *
- * Scores are calculated by field, using the query vectors created
- * above, and combined into a final document score using addition.
- */
- var fieldRef = lunr.FieldRef.fromString(matchingFieldRefs[i]),
- docRef = fieldRef.docRef
-
- if (!allRequiredMatches.contains(docRef)) {
- continue
- }
-
- if (allProhibitedMatches.contains(docRef)) {
- continue
- }
-
- var fieldVector = this.fieldVectors[fieldRef],
- score = queryVectors[fieldRef.fieldName].similarity(fieldVector),
- docMatch
-
- if ((docMatch = matches[docRef]) !== undefined) {
- docMatch.score += score
- docMatch.matchData.combine(matchingFields[fieldRef])
- } else {
- var match = {
- ref: docRef,
- score: score,
- matchData: matchingFields[fieldRef]
- }
- matches[docRef] = match
- results.push(match)
- }
- }
-
- /*
- * Sort the results objects by score, highest first.
- */
- return results.sort(function (a, b) {
- return b.score - a.score
- })
-}
-
-/**
- * Prepares the index for JSON serialization.
- *
- * The schema for this JSON blob will be described in a
- * separate JSON schema file.
- *
- * @returns {Object}
- */
-lunr.Index.prototype.toJSON = function () {
- var invertedIndex = Object.keys(this.invertedIndex)
- .sort()
- .map(function (term) {
- return [term, this.invertedIndex[term]]
- }, this)
-
- var fieldVectors = Object.keys(this.fieldVectors)
- .map(function (ref) {
- return [ref, this.fieldVectors[ref].toJSON()]
- }, this)
-
- return {
- version: lunr.version,
- fields: this.fields,
- fieldVectors: fieldVectors,
- invertedIndex: invertedIndex,
- pipeline: this.pipeline.toJSON()
- }
-}
-
-/**
- * Loads a previously serialized lunr.Index
- *
- * @param {Object} serializedIndex - A previously serialized lunr.Index
- * @returns {lunr.Index}
- */
-lunr.Index.load = function (serializedIndex) {
- var attrs = {},
- fieldVectors = {},
- serializedVectors = serializedIndex.fieldVectors,
- invertedIndex = {},
- serializedInvertedIndex = serializedIndex.invertedIndex,
- tokenSetBuilder = new lunr.TokenSet.Builder,
- pipeline = lunr.Pipeline.load(serializedIndex.pipeline)
-
- if (serializedIndex.version != lunr.version) {
- lunr.utils.warn("Version mismatch when loading serialised index. Current version of lunr '" + lunr.version + "' does not match serialized index '" + serializedIndex.version + "'")
- }
-
- for (var i = 0; i < serializedVectors.length; i++) {
- var tuple = serializedVectors[i],
- ref = tuple[0],
- elements = tuple[1]
-
- fieldVectors[ref] = new lunr.Vector(elements)
- }
-
- for (var i = 0; i < serializedInvertedIndex.length; i++) {
- var tuple = serializedInvertedIndex[i],
- term = tuple[0],
- posting = tuple[1]
-
- tokenSetBuilder.insert(term)
- invertedIndex[term] = posting
- }
-
- tokenSetBuilder.finish()
-
- attrs.fields = serializedIndex.fields
-
- attrs.fieldVectors = fieldVectors
- attrs.invertedIndex = invertedIndex
- attrs.tokenSet = tokenSetBuilder.root
- attrs.pipeline = pipeline
-
- return new lunr.Index(attrs)
-}
-/*!
- * lunr.Builder
- * Copyright (C) 2018 Oliver Nightingale
- */
-
-/**
- * lunr.Builder performs indexing on a set of documents and
- * returns instances of lunr.Index ready for querying.
- *
- * All configuration of the index is done via the builder, the
- * fields to index, the document reference, the text processing
- * pipeline and document scoring parameters are all set on the
- * builder before indexing.
- *
- * @constructor
- * @property {string} _ref - Internal reference to the document reference field.
- * @property {string[]} _fields - Internal reference to the document fields to index.
- * @property {object} invertedIndex - The inverted index maps terms to document fields.
- * @property {object} documentTermFrequencies - Keeps track of document term frequencies.
- * @property {object} documentLengths - Keeps track of the length of documents added to the index.
- * @property {lunr.tokenizer} tokenizer - Function for splitting strings into tokens for indexing.
- * @property {lunr.Pipeline} pipeline - The pipeline performs text processing on tokens before indexing.
- * @property {lunr.Pipeline} searchPipeline - A pipeline for processing search terms before querying the index.
- * @property {number} documentCount - Keeps track of the total number of documents indexed.
- * @property {number} _b - A parameter to control field length normalization, setting this to 0 disabled normalization, 1 fully normalizes field lengths, the default value is 0.75.
- * @property {number} _k1 - A parameter to control how quickly an increase in term frequency results in term frequency saturation, the default value is 1.2.
- * @property {number} termIndex - A counter incremented for each unique term, used to identify a terms position in the vector space.
- * @property {array} metadataWhitelist - A list of metadata keys that have been whitelisted for entry in the index.
- */
-lunr.Builder = function () {
- this._ref = "id"
- this._fields = Object.create(null)
- this._documents = Object.create(null)
- this.invertedIndex = Object.create(null)
- this.fieldTermFrequencies = {}
- this.fieldLengths = {}
- this.tokenizer = lunr.tokenizer
- this.pipeline = new lunr.Pipeline
- this.searchPipeline = new lunr.Pipeline
- this.documentCount = 0
- this._b = 0.75
- this._k1 = 1.2
- this.termIndex = 0
- this.metadataWhitelist = []
-}
-
-/**
- * Sets the document field used as the document reference. Every document must have this field.
- * The type of this field in the document should be a string, if it is not a string it will be
- * coerced into a string by calling toString.
- *
- * The default ref is 'id'.
- *
- * The ref should _not_ be changed during indexing, it should be set before any documents are
- * added to the index. Changing it during indexing can lead to inconsistent results.
- *
- * @param {string} ref - The name of the reference field in the document.
- */
-lunr.Builder.prototype.ref = function (ref) {
- this._ref = ref
-}
-
-/**
- * A function that is used to extract a field from a document.
- *
- * Lunr expects a field to be at the top level of a document, if however the field
- * is deeply nested within a document an extractor function can be used to extract
- * the right field for indexing.
- *
- * @callback fieldExtractor
- * @param {object} doc - The document being added to the index.
- * @returns {?(string|object|object[])} obj - The object that will be indexed for this field.
- * @example <caption>Extracting a nested field</caption>
- * function (doc) { return doc.nested.field }
- */
-
-/**
- * Adds a field to the list of document fields that will be indexed. Every document being
- * indexed should have this field. Null values for this field in indexed documents will
- * not cause errors but will limit the chance of that document being retrieved by searches.
- *
- * All fields should be added before adding documents to the index. Adding fields after
- * a document has been indexed will have no effect on already indexed documents.
- *
- * Fields can be boosted at build time. This allows terms within that field to have more
- * importance when ranking search results. Use a field boost to specify that matches within
- * one field are more important than other fields.
- *
- * @param {string} fieldName - The name of a field to index in all documents.
- * @param {object} attributes - Optional attributes associated with this field.
- * @param {number} [attributes.boost=1] - Boost applied to all terms within this field.
- * @param {fieldExtractor} [attributes.extractor] - Function to extract a field from a document.
- * @throws {RangeError} fieldName cannot contain unsupported characters '/'
- */
-lunr.Builder.prototype.field = function (fieldName, attributes) {
- if (/\//.test(fieldName)) {
- throw new RangeError ("Field '" + fieldName + "' contains illegal character '/'")
- }
-
- this._fields[fieldName] = attributes || {}
-}
-
-/**
- * A parameter to tune the amount of field length normalisation that is applied when
- * calculating relevance scores. A value of 0 will completely disable any normalisation
- * and a value of 1 will fully normalise field lengths. The default is 0.75. Values of b
- * will be clamped to the range 0 - 1.
- *
- * @param {number} number - The value to set for this tuning parameter.
- */
-lunr.Builder.prototype.b = function (number) {
- if (number < 0) {
- this._b = 0
- } else if (number > 1) {
- this._b = 1
- } else {
- this._b = number
- }
-}
-
-/**
- * A parameter that controls the speed at which a rise in term frequency results in term
- * frequency saturation. The default value is 1.2. Setting this to a higher value will give
- * slower saturation levels, a lower value will result in quicker saturation.
- *
- * @param {number} number - The value to set for this tuning parameter.
- */
-lunr.Builder.prototype.k1 = function (number) {
- this._k1 = number
-}
-
-/**
- * Adds a document to the index.
- *
- * Before adding fields to the index the index should have been fully setup, with the document
- * ref and all fields to index already having been specified.
- *
- * The document must have a field name as specified by the ref (by default this is 'id') and
- * it should have all fields defined for indexing, though null or undefined values will not
- * cause errors.
- *
- * Entire documents can be boosted at build time. Applying a boost to a document indicates that
- * this document should rank higher in search results than other documents.
- *
- * @param {object} doc - The document to add to the index.
- * @param {object} attributes - Optional attributes associated with this document.
- * @param {number} [attributes.boost=1] - Boost applied to all terms within this document.
- */
-lunr.Builder.prototype.add = function (doc, attributes) {
- var docRef = doc[this._ref],
- fields = Object.keys(this._fields)
-
- this._documents[docRef] = attributes || {}
- this.documentCount += 1
-
- for (var i = 0; i < fields.length; i++) {
- var fieldName = fields[i],
- extractor = this._fields[fieldName].extractor,
- field = extractor ? extractor(doc) : doc[fieldName],
- tokens = this.tokenizer(field, {
- fields: [fieldName]
- }),
- terms = this.pipeline.run(tokens),
- fieldRef = new lunr.FieldRef (docRef, fieldName),
- fieldTerms = Object.create(null)
-
- this.fieldTermFrequencies[fieldRef] = fieldTerms
- this.fieldLengths[fieldRef] = 0
-
- // store the length of this field for this document
- this.fieldLengths[fieldRef] += terms.length
-
- // calculate term frequencies for this field
- for (var j = 0; j < terms.length; j++) {
- var term = terms[j]
-
- if (fieldTerms[term] == undefined) {
- fieldTerms[term] = 0
- }
-
- fieldTerms[term] += 1
-
- // add to inverted index
- // create an initial posting if one doesn't exist
- if (this.invertedIndex[term] == undefined) {
- var posting = Object.create(null)
- posting["_index"] = this.termIndex
- this.termIndex += 1
-
- for (var k = 0; k < fields.length; k++) {
- posting[fields[k]] = Object.create(null)
- }
-
- this.invertedIndex[term] = posting
- }
-
- // add an entry for this term/fieldName/docRef to the invertedIndex
- if (this.invertedIndex[term][fieldName][docRef] == undefined) {
- this.invertedIndex[term][fieldName][docRef] = Object.create(null)
- }
-
- // store all whitelisted metadata about this token in the
- // inverted index
- for (var l = 0; l < this.metadataWhitelist.length; l++) {
- var metadataKey = this.metadataWhitelist[l],
- metadata = term.metadata[metadataKey]
-
- if (this.invertedIndex[term][fieldName][docRef][metadataKey] == undefined) {
- this.invertedIndex[term][fieldName][docRef][metadataKey] = []
- }
-
- this.invertedIndex[term][fieldName][docRef][metadataKey].push(metadata)
- }
- }
-
- }
-}
-
-/**
- * Calculates the average document length for this index
- *
- * @private
- */
-lunr.Builder.prototype.calculateAverageFieldLengths = function () {
-
- var fieldRefs = Object.keys(this.fieldLengths),
- numberOfFields = fieldRefs.length,
- accumulator = {},
- documentsWithField = {}
-
- for (var i = 0; i < numberOfFields; i++) {
- var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
- field = fieldRef.fieldName
-
- documentsWithField[field] || (documentsWithField[field] = 0)
- documentsWithField[field] += 1
-
- accumulator[field] || (accumulator[field] = 0)
- accumulator[field] += this.fieldLengths[fieldRef]
- }
-
- var fields = Object.keys(this._fields)
-
- for (var i = 0; i < fields.length; i++) {
- var fieldName = fields[i]
- accumulator[fieldName] = accumulator[fieldName] / documentsWithField[fieldName]
- }
-
- this.averageFieldLength = accumulator
-}
-
-/**
- * Builds a vector space model of every document using lunr.Vector
- *
- * @private
- */
-lunr.Builder.prototype.createFieldVectors = function () {
- var fieldVectors = {},
- fieldRefs = Object.keys(this.fieldTermFrequencies),
- fieldRefsLength = fieldRefs.length,
- termIdfCache = Object.create(null)
-
- for (var i = 0; i < fieldRefsLength; i++) {
- var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
- fieldName = fieldRef.fieldName,
- fieldLength = this.fieldLengths[fieldRef],
- fieldVector = new lunr.Vector,
- termFrequencies = this.fieldTermFrequencies[fieldRef],
- terms = Object.keys(termFrequencies),
- termsLength = terms.length
-
-
- var fieldBoost = this._fields[fieldName].boost || 1,
- docBoost = this._documents[fieldRef.docRef].boost || 1
-
- for (var j = 0; j < termsLength; j++) {
- var term = terms[j],
- tf = termFrequencies[term],
- termIndex = this.invertedIndex[term]._index,
- idf, score, scoreWithPrecision
-
- if (termIdfCache[term] === undefined) {
- idf = lunr.idf(this.invertedIndex[term], this.documentCount)
- termIdfCache[term] = idf
- } else {
- idf = termIdfCache[term]
- }
-
- score = idf * ((this._k1 + 1) * tf) / (this._k1 * (1 - this._b + this._b * (fieldLength / this.averageFieldLength[fieldName])) + tf)
- score *= fieldBoost
- score *= docBoost
- scoreWithPrecision = Math.round(score * 1000) / 1000
- // Converts 1.23456789 to 1.234.
- // Reducing the precision so that the vectors take up less
- // space when serialised. Doing it now so that they behave
- // the same before and after serialisation. Also, this is
- // the fastest approach to reducing a number's precision in
- // JavaScript.
-
- fieldVector.insert(termIndex, scoreWithPrecision)
- }
-
- fieldVectors[fieldRef] = fieldVector
- }
-
- this.fieldVectors = fieldVectors
-}
-
-/**
- * Creates a token set of all tokens in the index using lunr.TokenSet
- *
- * @private
- */
-lunr.Builder.prototype.createTokenSet = function () {
- this.tokenSet = lunr.TokenSet.fromArray(
- Object.keys(this.invertedIndex).sort()
- )
-}
-
-/**
- * Builds the index, creating an instance of lunr.Index.
- *
- * This completes the indexing process and should only be called
- * once all documents have been added to the index.
- *
- * @returns {lunr.Index}
- */
-lunr.Builder.prototype.build = function () {
- this.calculateAverageFieldLengths()
- this.createFieldVectors()
- this.createTokenSet()
-
- return new lunr.Index({
- invertedIndex: this.invertedIndex,
- fieldVectors: this.fieldVectors,
- tokenSet: this.tokenSet,
- fields: Object.keys(this._fields),
- pipeline: this.searchPipeline
- })
-}
-
-/**
- * Applies a plugin to the index builder.
- *
- * A plugin is a function that is called with the index builder as its context.
- * Plugins can be used to customise or extend the behaviour of the index
- * in some way. A plugin is just a function, that encapsulated the custom
- * behaviour that should be applied when building the index.
- *
- * The plugin function will be called with the index builder as its argument, additional
- * arguments can also be passed when calling use. The function will be called
- * with the index builder as its context.
- *
- * @param {Function} plugin The plugin to apply.
- */
-lunr.Builder.prototype.use = function (fn) {
- var args = Array.prototype.slice.call(arguments, 1)
- args.unshift(this)
- fn.apply(this, args)
-}
-/**
- * Contains and collects metadata about a matching document.
- * A single instance of lunr.MatchData is returned as part of every
- * lunr.Index~Result.
- *
- * @constructor
- * @param {string} term - The term this match data is associated with
- * @param {string} field - The field in which the term was found
- * @param {object} metadata - The metadata recorded about this term in this field
- * @property {object} metadata - A cloned collection of metadata associated with this document.
- * @see {@link lunr.Index~Result}
- */
-lunr.MatchData = function (term, field, metadata) {
- var clonedMetadata = Object.create(null),
- metadataKeys = Object.keys(metadata || {})
-
- // Cloning the metadata to prevent the original
- // being mutated during match data combination.
- // Metadata is kept in an array within the inverted
- // index so cloning the data can be done with
- // Array#slice
- for (var i = 0; i < metadataKeys.length; i++) {
- var key = metadataKeys[i]
- clonedMetadata[key] = metadata[key].slice()
- }
-
- this.metadata = Object.create(null)
-
- if (term !== undefined) {
- this.metadata[term] = Object.create(null)
- this.metadata[term][field] = clonedMetadata
- }
-}
-
-/**
- * An instance of lunr.MatchData will be created for every term that matches a
- * document. However only one instance is required in a lunr.Index~Result. This
- * method combines metadata from another instance of lunr.MatchData with this
- * objects metadata.
- *
- * @param {lunr.MatchData} otherMatchData - Another instance of match data to merge with this one.
- * @see {@link lunr.Index~Result}
- */
-lunr.MatchData.prototype.combine = function (otherMatchData) {
- var terms = Object.keys(otherMatchData.metadata)
-
- for (var i = 0; i < terms.length; i++) {
- var term = terms[i],
- fields = Object.keys(otherMatchData.metadata[term])
-
- if (this.metadata[term] == undefined) {
- this.metadata[term] = Object.create(null)
- }
-
- for (var j = 0; j < fields.length; j++) {
- var field = fields[j],
- keys = Object.keys(otherMatchData.metadata[term][field])
-
- if (this.metadata[term][field] == undefined) {
- this.metadata[term][field] = Object.create(null)
- }
-
- for (var k = 0; k < keys.length; k++) {
- var key = keys[k]
-
- if (this.metadata[term][field][key] == undefined) {
- this.metadata[term][field][key] = otherMatchData.metadata[term][field][key]
- } else {
- this.metadata[term][field][key] = this.metadata[term][field][key].concat(otherMatchData.metadata[term][field][key])
- }
-
- }
- }
- }
-}
-
-/**
- * Add metadata for a term/field pair to this instance of match data.
- *
- * @param {string} term - The term this match data is associated with
- * @param {string} field - The field in which the term was found
- * @param {object} metadata - The metadata recorded about this term in this field
- */
-lunr.MatchData.prototype.add = function (term, field, metadata) {
- if (!(term in this.metadata)) {
- this.metadata[term] = Object.create(null)
- this.metadata[term][field] = metadata
- return
- }
-
- if (!(field in this.metadata[term])) {
- this.metadata[term][field] = metadata
- return
- }
-
- var metadataKeys = Object.keys(metadata)
-
- for (var i = 0; i < metadataKeys.length; i++) {
- var key = metadataKeys[i]
-
- if (key in this.metadata[term][field]) {
- this.metadata[term][field][key] = this.metadata[term][field][key].concat(metadata[key])
- } else {
- this.metadata[term][field][key] = metadata[key]
- }
- }
-}
-/**
- * A lunr.Query provides a programmatic way of defining queries to be performed
- * against a {@link lunr.Index}.
- *
- * Prefer constructing a lunr.Query using the {@link lunr.Index#query} method
- * so the query object is pre-initialized with the right index fields.
- *
- * @constructor
- * @property {lunr.Query~Clause[]} clauses - An array of query clauses.
- * @property {string[]} allFields - An array of all available fields in a lunr.Index.
- */
-lunr.Query = function (allFields) {
- this.clauses = []
- this.allFields = allFields
-}
-
-/**
- * Constants for indicating what kind of automatic wildcard insertion will be used when constructing a query clause.
- *
- * This allows wildcards to be added to the beginning and end of a term without having to manually do any string
- * concatenation.
- *
- * The wildcard constants can be bitwise combined to select both leading and trailing wildcards.
- *
- * @constant
- * @default
- * @property {number} wildcard.NONE - The term will have no wildcards inserted, this is the default behaviour
- * @property {number} wildcard.LEADING - Prepend the term with a wildcard, unless a leading wildcard already exists
- * @property {number} wildcard.TRAILING - Append a wildcard to the term, unless a trailing wildcard already exists
- * @see lunr.Query~Clause
- * @see lunr.Query#clause
- * @see lunr.Query#term
- * @example <caption>query term with trailing wildcard</caption>
- * query.term('foo', { wildcard: lunr.Query.wildcard.TRAILING })
- * @example <caption>query term with leading and trailing wildcard</caption>
- * query.term('foo', {
- * wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING
- * })
- */
-
-lunr.Query.wildcard = new String ("*")
-lunr.Query.wildcard.NONE = 0
-lunr.Query.wildcard.LEADING = 1
-lunr.Query.wildcard.TRAILING = 2
-
-/**
- * Constants for indicating what kind of presence a term must have in matching documents.
- *
- * @constant
- * @enum {number}
- * @see lunr.Query~Clause
- * @see lunr.Query#clause
- * @see lunr.Query#term
- * @example <caption>query term with required presence</caption>
- * query.term('foo', { presence: lunr.Query.presence.REQUIRED })
- */
-lunr.Query.presence = {
- /**
- * Term's presence in a document is optional, this is the default value.
- */
- OPTIONAL: 1,
-
- /**
- * Term's presence in a document is required, documents that do not contain
- * this term will not be returned.
- */
- REQUIRED: 2,
-
- /**
- * Term's presence in a document is prohibited, documents that do contain
- * this term will not be returned.
- */
- PROHIBITED: 3
-}
-
-/**
- * A single clause in a {@link lunr.Query} contains a term and details on how to
- * match that term against a {@link lunr.Index}.
- *
- * @typedef {Object} lunr.Query~Clause
- * @property {string[]} fields - The fields in an index this clause should be matched against.
- * @property {number} [boost=1] - Any boost that should be applied when matching this clause.
- * @property {number} [editDistance] - Whether the term should have fuzzy matching applied, and how fuzzy the match should be.
- * @property {boolean} [usePipeline] - Whether the term should be passed through the search pipeline.
- * @property {number} [wildcard=lunr.Query.wildcard.NONE] - Whether the term should have wildcards appended or prepended.
- * @property {number} [presence=lunr.Query.presence.OPTIONAL] - The terms presence in any matching documents.
- */
-
-/**
- * Adds a {@link lunr.Query~Clause} to this query.
- *
- * Unless the clause contains the fields to be matched all fields will be matched. In addition
- * a default boost of 1 is applied to the clause.
- *
- * @param {lunr.Query~Clause} clause - The clause to add to this query.
- * @see lunr.Query~Clause
- * @returns {lunr.Query}
- */
-lunr.Query.prototype.clause = function (clause) {
- if (!('fields' in clause)) {
- clause.fields = this.allFields
- }
-
- if (!('boost' in clause)) {
- clause.boost = 1
- }
-
- if (!('usePipeline' in clause)) {
- clause.usePipeline = true
- }
-
- if (!('wildcard' in clause)) {
- clause.wildcard = lunr.Query.wildcard.NONE
- }
-
- if ((clause.wildcard & lunr.Query.wildcard.LEADING) && (clause.term.charAt(0) != lunr.Query.wildcard)) {
- clause.term = "*" + clause.term
- }
-
- if ((clause.wildcard & lunr.Query.wildcard.TRAILING) && (clause.term.slice(-1) != lunr.Query.wildcard)) {
- clause.term = "" + clause.term + "*"
- }
-
- if (!('presence' in clause)) {
- clause.presence = lunr.Query.presence.OPTIONAL
- }
-
- this.clauses.push(clause)
-
- return this
-}
-
-/**
- * A negated query is one in which every clause has a presence of
- * prohibited. These queries require some special processing to return
- * the expected results.
- *
- * @returns boolean
- */
-lunr.Query.prototype.isNegated = function () {
- for (var i = 0; i < this.clauses.length; i++) {
- if (this.clauses[i].presence != lunr.Query.presence.PROHIBITED) {
- return false
- }
- }
-
- return true
-}
-
-/**
- * Adds a term to the current query, under the covers this will create a {@link lunr.Query~Clause}
- * to the list of clauses that make up this query.
- *
- * The term is used as is, i.e. no tokenization will be performed by this method. Instead conversion
- * to a token or token-like string should be done before calling this method.
- *
- * The term will be converted to a string by calling `toString`. Multiple terms can be passed as an
- * array, each term in the array will share the same options.
- *
- * @param {object|object[]} term - The term(s) to add to the query.
- * @param {object} [options] - Any additional properties to add to the query clause.
- * @returns {lunr.Query}
- * @see lunr.Query#clause
- * @see lunr.Query~Clause
- * @example <caption>adding a single term to a query</caption>
- * query.term("foo")
- * @example <caption>adding a single term to a query and specifying search fields, term boost and automatic trailing wildcard</caption>
- * query.term("foo", {
- * fields: ["title"],
- * boost: 10,
- * wildcard: lunr.Query.wildcard.TRAILING
- * })
- * @example <caption>using lunr.tokenizer to convert a string to tokens before using them as terms</caption>
- * query.term(lunr.tokenizer("foo bar"))
- */
-lunr.Query.prototype.term = function (term, options) {
- if (Array.isArray(term)) {
- term.forEach(function (t) { this.term(t, lunr.utils.clone(options)) }, this)
- return this
- }
-
- var clause = options || {}
- clause.term = term.toString()
-
- this.clause(clause)
-
- return this
-}
-lunr.QueryParseError = function (message, start, end) {
- this.name = "QueryParseError"
- this.message = message
- this.start = start
- this.end = end
-}
-
-lunr.QueryParseError.prototype = new Error
-lunr.QueryLexer = function (str) {
- this.lexemes = []
- this.str = str
- this.length = str.length
- this.pos = 0
- this.start = 0
- this.escapeCharPositions = []
-}
-
-lunr.QueryLexer.prototype.run = function () {
- var state = lunr.QueryLexer.lexText
-
- while (state) {
- state = state(this)
- }
-}
-
-lunr.QueryLexer.prototype.sliceString = function () {
- var subSlices = [],
- sliceStart = this.start,
- sliceEnd = this.pos
-
- for (var i = 0; i < this.escapeCharPositions.length; i++) {
- sliceEnd = this.escapeCharPositions[i]
- subSlices.push(this.str.slice(sliceStart, sliceEnd))
- sliceStart = sliceEnd + 1
- }
-
- subSlices.push(this.str.slice(sliceStart, this.pos))
- this.escapeCharPositions.length = 0
-
- return subSlices.join('')
-}
-
-lunr.QueryLexer.prototype.emit = function (type) {
- this.lexemes.push({
- type: type,
- str: this.sliceString(),
- start: this.start,
- end: this.pos
- })
-
- this.start = this.pos
-}
-
-lunr.QueryLexer.prototype.escapeCharacter = function () {
- this.escapeCharPositions.push(this.pos - 1)
- this.pos += 1
-}
-
-lunr.QueryLexer.prototype.next = function () {
- if (this.pos >= this.length) {
- return lunr.QueryLexer.EOS
- }
-
- var char = this.str.charAt(this.pos)
- this.pos += 1
- return char
-}
-
-lunr.QueryLexer.prototype.width = function () {
- return this.pos - this.start
-}
-
-lunr.QueryLexer.prototype.ignore = function () {
- if (this.start == this.pos) {
- this.pos += 1
- }
-
- this.start = this.pos
-}
-
-lunr.QueryLexer.prototype.backup = function () {
- this.pos -= 1
-}
-
-lunr.QueryLexer.prototype.acceptDigitRun = function () {
- var char, charCode
-
- do {
- char = this.next()
- charCode = char.charCodeAt(0)
- } while (charCode > 47 && charCode < 58)
-
- if (char != lunr.QueryLexer.EOS) {
- this.backup()
- }
-}
-
-lunr.QueryLexer.prototype.more = function () {
- return this.pos < this.length
-}
-
-lunr.QueryLexer.EOS = 'EOS'
-lunr.QueryLexer.FIELD = 'FIELD'
-lunr.QueryLexer.TERM = 'TERM'
-lunr.QueryLexer.EDIT_DISTANCE = 'EDIT_DISTANCE'
-lunr.QueryLexer.BOOST = 'BOOST'
-lunr.QueryLexer.PRESENCE = 'PRESENCE'
-
-lunr.QueryLexer.lexField = function (lexer) {
- lexer.backup()
- lexer.emit(lunr.QueryLexer.FIELD)
- lexer.ignore()
- return lunr.QueryLexer.lexText
-}
-
-lunr.QueryLexer.lexTerm = function (lexer) {
- if (lexer.width() > 1) {
- lexer.backup()
- lexer.emit(lunr.QueryLexer.TERM)
- }
-
- lexer.ignore()
-
- if (lexer.more()) {
- return lunr.QueryLexer.lexText
- }
-}
-
-lunr.QueryLexer.lexEditDistance = function (lexer) {
- lexer.ignore()
- lexer.acceptDigitRun()
- lexer.emit(lunr.QueryLexer.EDIT_DISTANCE)
- return lunr.QueryLexer.lexText
-}
-
-lunr.QueryLexer.lexBoost = function (lexer) {
- lexer.ignore()
- lexer.acceptDigitRun()
- lexer.emit(lunr.QueryLexer.BOOST)
- return lunr.QueryLexer.lexText
-}
-
-lunr.QueryLexer.lexEOS = function (lexer) {
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
-}
-
-// This matches the separator used when tokenising fields
-// within a document. These should match otherwise it is
-// not possible to search for some tokens within a document.
-//
-// It is possible for the user to change the separator on the
-// tokenizer so it _might_ clash with any other of the special
-// characters already used within the search string, e.g. :.
-//
-// This means that it is possible to change the separator in
-// such a way that makes some words unsearchable using a search
-// string.
-lunr.QueryLexer.termSeparator = lunr.tokenizer.separator
-
-lunr.QueryLexer.lexText = function (lexer) {
- while (true) {
- var char = lexer.next()
-
- if (char == lunr.QueryLexer.EOS) {
- return lunr.QueryLexer.lexEOS
- }
-
- // Escape character is '\'
- if (char.charCodeAt(0) == 92) {
- lexer.escapeCharacter()
- continue
- }
-
- if (char == ":") {
- return lunr.QueryLexer.lexField
- }
-
- if (char == "~") {
- lexer.backup()
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
- return lunr.QueryLexer.lexEditDistance
- }
-
- if (char == "^") {
- lexer.backup()
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
- return lunr.QueryLexer.lexBoost
- }
-
- // "+" indicates term presence is required
- // checking for length to ensure that only
- // leading "+" are considered
- if (char == "+" && lexer.width() === 1) {
- lexer.emit(lunr.QueryLexer.PRESENCE)
- return lunr.QueryLexer.lexText
- }
-
- // "-" indicates term presence is prohibited
- // checking for length to ensure that only
- // leading "-" are considered
- if (char == "-" && lexer.width() === 1) {
- lexer.emit(lunr.QueryLexer.PRESENCE)
- return lunr.QueryLexer.lexText
- }
-
- if (char.match(lunr.QueryLexer.termSeparator)) {
- return lunr.QueryLexer.lexTerm
- }
- }
-}
-
-lunr.QueryParser = function (str, query) {
- this.lexer = new lunr.QueryLexer (str)
- this.query = query
- this.currentClause = {}
- this.lexemeIdx = 0
-}
-
-lunr.QueryParser.prototype.parse = function () {
- this.lexer.run()
- this.lexemes = this.lexer.lexemes
-
- var state = lunr.QueryParser.parseClause
-
- while (state) {
- state = state(this)
- }
-
- return this.query
-}
-
-lunr.QueryParser.prototype.peekLexeme = function () {
- return this.lexemes[this.lexemeIdx]
-}
-
-lunr.QueryParser.prototype.consumeLexeme = function () {
- var lexeme = this.peekLexeme()
- this.lexemeIdx += 1
- return lexeme
-}
-
-lunr.QueryParser.prototype.nextClause = function () {
- var completedClause = this.currentClause
- this.query.clause(completedClause)
- this.currentClause = {}
-}
-
-lunr.QueryParser.parseClause = function (parser) {
- var lexeme = parser.peekLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- switch (lexeme.type) {
- case lunr.QueryLexer.PRESENCE:
- return lunr.QueryParser.parsePresence
- case lunr.QueryLexer.FIELD:
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expected either a field or a term, found " + lexeme.type
-
- if (lexeme.str.length >= 1) {
- errorMessage += " with value '" + lexeme.str + "'"
- }
-
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-}
-
-lunr.QueryParser.parsePresence = function (parser) {
- var lexeme = parser.consumeLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- switch (lexeme.str) {
- case "-":
- parser.currentClause.presence = lunr.Query.presence.PROHIBITED
- break
- case "+":
- parser.currentClause.presence = lunr.Query.presence.REQUIRED
- break
- default:
- var errorMessage = "unrecognised presence operator'" + lexeme.str + "'"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- var nextLexeme = parser.peekLexeme()
-
- if (nextLexeme == undefined) {
- var errorMessage = "expecting term or field, found nothing"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- switch (nextLexeme.type) {
- case lunr.QueryLexer.FIELD:
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expecting term or field, found '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
-}
-
-lunr.QueryParser.parseField = function (parser) {
- var lexeme = parser.consumeLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- if (parser.query.allFields.indexOf(lexeme.str) == -1) {
- var possibleFields = parser.query.allFields.map(function (f) { return "'" + f + "'" }).join(', '),
- errorMessage = "unrecognised field '" + lexeme.str + "', possible fields: " + possibleFields
-
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- parser.currentClause.fields = [lexeme.str]
-
- var nextLexeme = parser.peekLexeme()
-
- if (nextLexeme == undefined) {
- var errorMessage = "expecting term, found nothing"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expecting term, found '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
-}
-
-lunr.QueryParser.parseTerm = function (parser) {
- var lexeme = parser.consumeLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- parser.currentClause.term = lexeme.str.toLowerCase()
-
- if (lexeme.str.indexOf("*") != -1) {
- parser.currentClause.usePipeline = false
- }
-
- var nextLexeme = parser.peekLexeme()
-
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
-
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
-}
-
-lunr.QueryParser.parseEditDistance = function (parser) {
- var lexeme = parser.consumeLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- var editDistance = parseInt(lexeme.str, 10)
-
- if (isNaN(editDistance)) {
- var errorMessage = "edit distance must be numeric"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- parser.currentClause.editDistance = editDistance
-
- var nextLexeme = parser.peekLexeme()
-
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
-
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
-}
-
-lunr.QueryParser.parseBoost = function (parser) {
- var lexeme = parser.consumeLexeme()
-
- if (lexeme == undefined) {
- return
- }
-
- var boost = parseInt(lexeme.str, 10)
-
- if (isNaN(boost)) {
- var errorMessage = "boost must be numeric"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
-
- parser.currentClause.boost = boost
-
- var nextLexeme = parser.peekLexeme()
-
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
-
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
-}
-
- /**
- * 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 enviroments that support module.exports,
- * like Node.
- */
- module.exports = factory()
- } else {
- // Browser globals (root is window)
- root.lunr = factory()
- }
- }(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 lunr
- }))
-})();
diff --git a/static/js/lunr.stemmer.support.js b/static/js/lunr.stemmer.support.js
deleted file mode 100644
index 896476a..0000000
--- a/static/js/lunr.stemmer.support.js
+++ /dev/null
@@ -1,304 +0,0 @@
-/*!
- * 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) {
- /* provides utilities for the included stemmers */
- lunr.stemmerSupport = {
- Among: function(s, substring_i, result, method) {
- this.toCharArray = function(s) {
- var sLength = s.length, charArr = new Array(sLength);
- for (var i = 0; i < sLength; i++)
- charArr[i] = s.charCodeAt(i);
- return charArr;
- };
-
- if ((!s && s != "") || (!substring_i && (substring_i != 0)) || !result)
- throw ("Bad Among initialisation: s:" + s + ", substring_i: "
- + substring_i + ", result: " + result);
- this.s_size = s.length;
- this.s = this.toCharArray(s);
- this.substring_i = substring_i;
- this.result = result;
- this.method = method;
- },
- SnowballProgram: function() {
- var current;
- return {
- bra : 0,
- ket : 0,
- limit : 0,
- cursor : 0,
- limit_backward : 0,
- setCurrent : function(word) {
- current = word;
- this.cursor = 0;
- this.limit = word.length;
- this.limit_backward = 0;
- this.bra = this.cursor;
- this.ket = this.limit;
- },
- getCurrent : function() {
- var result = current;
- current = null;
- return result;
- },
- in_grouping : function(s, min, max) {
- if (this.cursor < this.limit) {
- var ch = current.charCodeAt(this.cursor);
- if (ch <= max && ch >= min) {
- ch -= min;
- if (s[ch >> 3] & (0X1 << (ch & 0X7))) {
- this.cursor++;
- return true;
- }
- }
- }
- return false;
- },
- in_grouping_b : function(s, min, max) {
- if (this.cursor > this.limit_backward) {
- var ch = current.charCodeAt(this.cursor - 1);
- if (ch <= max && ch >= min) {
- ch -= min;
- if (s[ch >> 3] & (0X1 << (ch & 0X7))) {
- this.cursor--;
- return true;
- }
- }
- }
- return false;
- },
- out_grouping : function(s, min, max) {
- if (this.cursor < this.limit) {
- var ch = current.charCodeAt(this.cursor);
- if (ch > max || ch < min) {
- this.cursor++;
- return true;
- }
- ch -= min;
- if (!(s[ch >> 3] & (0X1 << (ch & 0X7)))) {
- this.cursor++;
- return true;
- }
- }
- return false;
- },
- out_grouping_b : function(s, min, max) {
- if (this.cursor > this.limit_backward) {
- var ch = current.charCodeAt(this.cursor - 1);
- if (ch > max || ch < min) {
- this.cursor--;
- return true;
- }
- ch -= min;
- if (!(s[ch >> 3] & (0X1 << (ch & 0X7)))) {
- this.cursor--;
- return true;
- }
- }
- return false;
- },
- eq_s : function(s_size, s) {
- if (this.limit - this.cursor < s_size)
- return false;
- for (var i = 0; i < s_size; i++)
- if (current.charCodeAt(this.cursor + i) != s.charCodeAt(i))
- return false;
- this.cursor += s_size;
- return true;
- },
- eq_s_b : function(s_size, s) {
- if (this.cursor - this.limit_backward < s_size)
- return false;
- for (var i = 0; i < s_size; i++)
- if (current.charCodeAt(this.cursor - s_size + i) != s
- .charCodeAt(i))
- return false;
- this.cursor -= s_size;
- return true;
- },
- find_among : function(v, v_size) {
- var i = 0, j = v_size, c = this.cursor, l = this.limit, common_i = 0, common_j = 0, first_key_inspected = false;
- while (true) {
- var k = i + ((j - i) >> 1), diff = 0, common = common_i < common_j
- ? common_i
- : common_j, w = v[k];
- for (var i2 = common; i2 < w.s_size; i2++) {
- if (c + common == l) {
- diff = -1;
- break;
- }
- diff = current.charCodeAt(c + common) - w.s[i2];
- if (diff)
- break;
- common++;
- }
- if (diff < 0) {
- j = k;
- common_j = common;
- } else {
- i = k;
- common_i = common;
- }
- if (j - i <= 1) {
- if (i > 0 || j == i || first_key_inspected)
- break;
- first_key_inspected = true;
- }
- }
- while (true) {
- var w = v[i];
- if (common_i >= w.s_size) {
- this.cursor = c + w.s_size;
- if (!w.method)
- return w.result;
- var res = w.method();
- this.cursor = c + w.s_size;
- if (res)
- return w.result;
- }
- i = w.substring_i;
- if (i < 0)
- return 0;
- }
- },
- find_among_b : function(v, v_size) {
- var i = 0, j = v_size, c = this.cursor, lb = this.limit_backward, common_i = 0, common_j = 0, first_key_inspected = false;
- while (true) {
- var k = i + ((j - i) >> 1), diff = 0, common = common_i < common_j
- ? common_i
- : common_j, w = v[k];
- for (var i2 = w.s_size - 1 - common; i2 >= 0; i2--) {
- if (c - common == lb) {
- diff = -1;
- break;
- }
- diff = current.charCodeAt(c - 1 - common) - w.s[i2];
- if (diff)
- break;
- common++;
- }
- if (diff < 0) {
- j = k;
- common_j = common;
- } else {
- i = k;
- common_i = common;
- }
- if (j - i <= 1) {
- if (i > 0 || j == i || first_key_inspected)
- break;
- first_key_inspected = true;
- }
- }
- while (true) {
- var w = v[i];
- if (common_i >= w.s_size) {
- this.cursor = c - w.s_size;
- if (!w.method)
- return w.result;
- var res = w.method();
- this.cursor = c - w.s_size;
- if (res)
- return w.result;
- }
- i = w.substring_i;
- if (i < 0)
- return 0;
- }
- },
- replace_s : function(c_bra, c_ket, s) {
- var adjustment = s.length - (c_ket - c_bra), left = current
- .substring(0, c_bra), right = current.substring(c_ket);
- current = left + s + right;
- this.limit += adjustment;
- if (this.cursor >= c_ket)
- this.cursor += adjustment;
- else if (this.cursor > c_bra)
- this.cursor = c_bra;
- return adjustment;
- },
- slice_check : function() {
- if (this.bra < 0 || this.bra > this.ket || this.ket > this.limit
- || this.limit > current.length)
- throw ("faulty slice operation");
- },
- slice_from : function(s) {
- this.slice_check();
- this.replace_s(this.bra, this.ket, s);
- },
- slice_del : function() {
- this.slice_from("");
- },
- insert : function(c_bra, c_ket, s) {
- var adjustment = this.replace_s(c_bra, c_ket, s);
- if (c_bra <= this.bra)
- this.bra += adjustment;
- if (c_bra <= this.ket)
- this.ket += adjustment;
- },
- slice_to : function() {
- this.slice_check();
- return current.substring(this.bra, this.ket);
- },
- eq_v_b : function(s) {
- return this.eq_s_b(s.length, s);
- }
- };
- }
- };
-
- lunr.trimmerSupport = {
- generateTrimmer: function(wordCharacters) {
- var startRegex = new RegExp("^[^" + wordCharacters + "]+")
- var endRegex = new RegExp("[^" + wordCharacters + "]+$")
-
- return function(token) {
- // for lunr version 2
- if (typeof token.update === "function") {
- return token.update(function (s) {
- return s
- .replace(startRegex, '')
- .replace(endRegex, '');
- })
- } else { // for lunr version 1
- return token
- .replace(startRegex, '')
- .replace(endRegex, '');
- }
- };
- }
- }
- }
-}));
diff --git a/static/js/search.js b/static/js/search.js
index 03760e5..b29d406 100644
--- a/static/js/search.js
+++ b/static/js/search.js
@@ -1,23 +1,19 @@
-var lunrIndex
-var lunrResult
-var pagesIndex
+var fuse
/**
- * Preparation for using lunr.js
+ * Preparation for searching
*/
-function initLunr () {
+function initSearch () {
$.getJSON('index.json').done(function (index) {
- pagesIndex = index
- lunrIndex = lunr(function () {
- this.use(lunr.ja)
- this.ref('ref')
- this.field('title', { boost: 10 })
- this.field('body')
- this.metadataWhitelist = ['position']
- pagesIndex.forEach(function (page) {
- this.add(page)
- }, this)
- })
+ var options = {
+ shouldSort: true,
+ tokenize: true,
+ matchAllTokens: true,
+ threshold: 0.3,
+ minMatchCharLength: 5,
+ keys: ['title', 'body']
+ }
+ fuse = new Fuse(index, options)
}).fail(function (jqxhr, textStatus, error) {
var err = textStatus + ', ' + error
console.error('Error getting Hugo index flie:', err)
@@ -25,20 +21,6 @@ function initLunr () {
}
/**
- * Searching pages using lunr
- * @param {String} query Query string for searching
- * @return {Object[]} Array of search results
- */
-function search (query) {
- lunrResult = lunrIndex.search(query)
- return lunrResult.map(function (result) {
- return pagesIndex.filter(function (page) {
- return page.ref === result.ref
- })[0]
- })
-}
-
-/**
* Setup UI for Search
*/
function initUI () {
@@ -51,7 +33,7 @@ function initUI () {
// Event when chenging query
$('#searchBox').keyup(function () {
var $searchResults = $('#searchResults')
- var query = $(this).val()
+ var query = $(this).val().trim()
// Icon switching
if (query.length) {
@@ -69,7 +51,7 @@ function initUI () {
}
// Display search results
- renderResults(search(query))
+ renderResults(fuse.search(query))
$searchResults.show()
})
@@ -84,7 +66,7 @@ function initUI () {
function renderResults (results) {
var $searchResults = $('#searchResults')
var query = $('#searchBox').val()
- var BODY_LENGTH = 100
+ var SUMMARY_INCLUDE = 100
var MAX_PAGES = 10
// Clear search result
@@ -99,13 +81,10 @@ function renderResults (results) {
// Only show the ten first results
results.slice(0, MAX_PAGES).forEach(function (result, idx) {
var $searchResultPage = $('<div class="searchResultPage">')
- var metadata = lunrResult[idx].matchData.metadata
- var matchPosition = metadata[Object.keys(metadata)[0]].body ? metadata[Object.keys(metadata)[0]].body.position[0][0] : 0
- var bodyStartPosition = (matchPosition - (BODY_LENGTH / 2) > 0) ? matchPosition - (BODY_LENGTH / 2) : 0
-
+ var matchPosition = result.body.indexOf(query.split(' ')[0])
+ var bodyStartPosition = matchPosition - SUMMARY_INCLUDE > 0 ? matchPosition - SUMMARY_INCLUDE : 0
$searchResultPage.append('<a class="searchResultTitle" href="' + result.ref + '">' + result.title + '</a>')
-
- $searchResultPage.append('<div class="searchResultBody">' + result.body.substr(bodyStartPosition, BODY_LENGTH) + '</div>')
+ $searchResultPage.append('<div class="searchResultBody">' + result.body.substr(bodyStartPosition, SUMMARY_INCLUDE) + '</div>')
$searchResults.append($searchResultPage)
// Highlight keyword
@@ -113,7 +92,7 @@ function renderResults (results) {
})
}
-initLunr()
+initSearch()
$(function () {
initUI()
diff --git a/static/js/tinyseg.js b/static/js/tinyseg.js
deleted file mode 100644
index 0b07714..0000000
--- a/static/js/tinyseg.js
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * 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) {
- // TinySegmenter 0.1 -- Super compact Japanese tokenizer in Javascript
- // (c) 2008 Taku Kudo <taku@chasen.org>
- // TinySegmenter is freely distributable under the terms of a new BSD licence.
- // For details, see http://chasen.org/~taku/software/TinySegmenter/LICENCE.txt
-
- function TinySegmenter() {
- var patterns = {
- "[一二三四五六七八九十百千万億兆]":"M",
- "[一-龠々〆ヵヶ]":"H",
- "[ぁ-ん]":"I",
- "[ァ-ヴーア-ン゙ー]":"K",
- "[a-zA-Za-zA-Z]":"A",
- "[0-90-9]":"N"
- }
- this.chartype_ = [];
- for (var i in patterns) {
- var regexp = new RegExp;
- regexp.compile(i)
- this.chartype_.push([regexp, patterns[i]]);
- }
-
- this.BIAS__ = -332
- this.BC1__ = {"HH":6,"II":2461,"KH":406,"OH":-1378};
- this.BC2__ = {"AA":-3267,"AI":2744,"AN":-878,"HH":-4070,"HM":-1711,"HN":4012,"HO":3761,"IA":1327,"IH":-1184,"II":-1332,"IK":1721,"IO":5492,"KI":3831,"KK":-8741,"MH":-3132,"MK":3334,"OO":-2920};
- this.BC3__ = {"HH":996,"HI":626,"HK":-721,"HN":-1307,"HO":-836,"IH":-301,"KK":2762,"MK":1079,"MM":4034,"OA":-1652,"OH":266};
- this.BP1__ = {"BB":295,"OB":304,"OO":-125,"UB":352};
- this.BP2__ = {"BO":60,"OO":-1762};
- this.BQ1__ = {"BHH":1150,"BHM":1521,"BII":-1158,"BIM":886,"BMH":1208,"BNH":449,"BOH":-91,"BOO":-2597,"OHI":451,"OIH":-296,"OKA":1851,"OKH":-1020,"OKK":904,"OOO":2965};
- this.BQ2__ = {"BHH":118,"BHI":-1159,"BHM":466,"BIH":-919,"BKK":-1720,"BKO":864,"OHH":-1139,"OHM":-181,"OIH":153,"UHI":-1146};
- this.BQ3__ = {"BHH":-792,"BHI":2664,"BII":-299,"BKI":419,"BMH":937,"BMM":8335,"BNN":998,"BOH":775,"OHH":2174,"OHM":439,"OII":280,"OKH":1798,"OKI":-793,"OKO":-2242,"OMH":-2402,"OOO":11699};
- this.BQ4__ = {"BHH":-3895,"BIH":3761,"BII":-4654,"BIK":1348,"BKK":-1806,"BMI":-3385,"BOO":-12396,"OAH":926,"OHH":266,"OHK":-2036,"ONN":-973};
- this.BW1__ = {",と":660,",同":727,"B1あ":1404,"B1同":542,"、と":660,"、同":727,"」と":1682,"あっ":1505,"いう":1743,"いっ":-2055,"いる":672,"うし":-4817,"うん":665,"から":3472,"がら":600,"こう":-790,"こと":2083,"こん":-1262,"さら":-4143,"さん":4573,"した":2641,"して":1104,"すで":-3399,"そこ":1977,"それ":-871,"たち":1122,"ため":601,"った":3463,"つい":-802,"てい":805,"てき":1249,"でき":1127,"です":3445,"では":844,"とい":-4915,"とみ":1922,"どこ":3887,"ない":5713,"なっ":3015,"など":7379,"なん":-1113,"にし":2468,"には":1498,"にも":1671,"に対":-912,"の一":-501,"の中":741,"ませ":2448,"まで":1711,"まま":2600,"まる":-2155,"やむ":-1947,"よっ":-2565,"れた":2369,"れで":-913,"をし":1860,"を見":731,"亡く":-1886,"京都":2558,"取り":-2784,"大き":-2604,"大阪":1497,"平方":-2314,"引き":-1336,"日本":-195,"本当":-2423,"毎日":-2113,"目指":-724,"B1あ":1404,"B1同":542,"」と":1682};
- this.BW2__ = {"..":-11822,"11":-669,"――":-5730,"−−":-13175,"いう":-1609,"うか":2490,"かし":-1350,"かも":-602,"から":-7194,"かれ":4612,"がい":853,"がら":-3198,"きた":1941,"くな":-1597,"こと":-8392,"この":-4193,"させ":4533,"され":13168,"さん":-3977,"しい":-1819,"しか":-545,"した":5078,"して":972,"しな":939,"その":-3744,"たい":-1253,"たた":-662,"ただ":-3857,"たち":-786,"たと":1224,"たは":-939,"った":4589,"って":1647,"っと":-2094,"てい":6144,"てき":3640,"てく":2551,"ては":-3110,"ても":-3065,"でい":2666,"でき":-1528,"でし":-3828,"です":-4761,"でも":-4203,"とい":1890,"とこ":-1746,"とと":-2279,"との":720,"とみ":5168,"とも":-3941,"ない":-2488,"なが":-1313,"など":-6509,"なの":2614,"なん":3099,"にお":-1615,"にし":2748,"にな":2454,"によ":-7236,"に対":-14943,"に従":-4688,"に関":-11388,"のか":2093,"ので":-7059,"のに":-6041,"のの":-6125,"はい":1073,"はが":-1033,"はず":-2532,"ばれ":1813,"まし":-1316,"まで":-6621,"まれ":5409,"めて":-3153,"もい":2230,"もの":-10713,"らか":-944,"らし":-1611,"らに":-1897,"りし":651,"りま":1620,"れた":4270,"れて":849,"れば":4114,"ろう":6067,"われ":7901,"を通":-11877,"んだ":728,"んな":-4115,"一人":602,"一方":-1375,"一日":970,"一部":-1051,"上が":-4479,"会社":-1116,"出て":2163,"分の":-7758,"同党":970,"同日":-913,"大阪":-2471,"委員":-1250,"少な":-1050,"年度":-8669,"年間":-1626,"府県":-2363,"手権":-1982,"新聞":-4066,"日新":-722,"日本":-7068,"日米":3372,"曜日":-601,"朝鮮":-2355,"本人":-2697,"東京":-1543,"然と":-1384,"社会":-1276,"立て":-990,"第に":-1612,"米国":-4268,"11":-669};
- this.BW3__ = {"あた":-2194,"あり":719,"ある":3846,"い.":-1185,"い。":-1185,"いい":5308,"いえ":2079,"いく":3029,"いた":2056,"いっ":1883,"いる":5600,"いわ":1527,"うち":1117,"うと":4798,"えと":1454,"か.":2857,"か。":2857,"かけ":-743,"かっ":-4098,"かに":-669,"から":6520,"かり":-2670,"が,":1816,"が、":1816,"がき":-4855,"がけ":-1127,"がっ":-913,"がら":-4977,"がり":-2064,"きた":1645,"けど":1374,"こと":7397,"この":1542,"ころ":-2757,"さい":-714,"さを":976,"し,":1557,"し、":1557,"しい":-3714,"した":3562,"して":1449,"しな":2608,"しま":1200,"す.":-1310,"す。":-1310,"する":6521,"ず,":3426,"ず、":3426,"ずに":841,"そう":428,"た.":8875,"た。":8875,"たい":-594,"たの":812,"たり":-1183,"たる":-853,"だ.":4098,"だ。":4098,"だっ":1004,"った":-4748,"って":300,"てい":6240,"てお":855,"ても":302,"です":1437,"でに":-1482,"では":2295,"とう":-1387,"とし":2266,"との":541,"とも":-3543,"どう":4664,"ない":1796,"なく":-903,"など":2135,"に,":-1021,"に、":-1021,"にし":1771,"にな":1906,"には":2644,"の,":-724,"の、":-724,"の子":-1000,"は,":1337,"は、":1337,"べき":2181,"まし":1113,"ます":6943,"まっ":-1549,"まで":6154,"まれ":-793,"らし":1479,"られ":6820,"るる":3818,"れ,":854,"れ、":854,"れた":1850,"れて":1375,"れば":-3246,"れる":1091,"われ":-605,"んだ":606,"んで":798,"カ月":990,"会議":860,"入り":1232,"大会":2217,"始め":1681,"市":965,"新聞":-5055,"日,":974,"日、":974,"社会":2024,"カ月":990};
- this.TC1__ = {"AAA":1093,"HHH":1029,"HHM":580,"HII":998,"HOH":-390,"HOM":-331,"IHI":1169,"IOH":-142,"IOI":-1015,"IOM":467,"MMH":187,"OOI":-1832};
- this.TC2__ = {"HHO":2088,"HII":-1023,"HMM":-1154,"IHI":-1965,"KKH":703,"OII":-2649};
- this.TC3__ = {"AAA":-294,"HHH":346,"HHI":-341,"HII":-1088,"HIK":731,"HOH":-1486,"IHH":128,"IHI":-3041,"IHO":-1935,"IIH":-825,"IIM":-1035,"IOI":-542,"KHH":-1216,"KKA":491,"KKH":-1217,"KOK":-1009,"MHH":-2694,"MHM":-457,"MHO":123,"MMH":-471,"NNH":-1689,"NNO":662,"OHO":-3393};
- this.TC4__ = {"HHH":-203,"HHI":1344,"HHK":365,"HHM":-122,"HHN":182,"HHO":669,"HIH":804,"HII":679,"HOH":446,"IHH":695,"IHO":-2324,"IIH":321,"III":1497,"IIO":656,"IOO":54,"KAK":4845,"KKA":3386,"KKK":3065,"MHH":-405,"MHI":201,"MMH":-241,"MMM":661,"MOM":841};
- this.TQ1__ = {"BHHH":-227,"BHHI":316,"BHIH":-132,"BIHH":60,"BIII":1595,"BNHH":-744,"BOHH":225,"BOOO":-908,"OAKK":482,"OHHH":281,"OHIH":249,"OIHI":200,"OIIH":-68};
- this.TQ2__ = {"BIHH":-1401,"BIII":-1033,"BKAK":-543,"BOOO":-5591};
- this.TQ3__ = {"BHHH":478,"BHHM":-1073,"BHIH":222,"BHII":-504,"BIIH":-116,"BIII":-105,"BMHI":-863,"BMHM":-464,"BOMH":620,"OHHH":346,"OHHI":1729,"OHII":997,"OHMH":481,"OIHH":623,"OIIH":1344,"OKAK":2792,"OKHH":587,"OKKA":679,"OOHH":110,"OOII":-685};
- this.TQ4__ = {"BHHH":-721,"BHHM":-3604,"BHII":-966,"BIIH":-607,"BIII":-2181,"OAAA":-2763,"OAKK":180,"OHHH":-294,"OHHI":2446,"OHHO":480,"OHIH":-1573,"OIHH":1935,"OIHI":-493,"OIIH":626,"OIII":-4007,"OKAK":-8156};
- this.TW1__ = {"につい":-4681,"東京都":2026};
- this.TW2__ = {"ある程":-2049,"いった":-1256,"ころが":-2434,"しょう":3873,"その後":-4430,"だって":-1049,"ていた":1833,"として":-4657,"ともに":-4517,"もので":1882,"一気に":-792,"初めて":-1512,"同時に":-8097,"大きな":-1255,"対して":-2721,"社会党":-3216};
- this.TW3__ = {"いただ":-1734,"してい":1314,"として":-4314,"につい":-5483,"にとっ":-5989,"に当た":-6247,"ので,":-727,"ので、":-727,"のもの":-600,"れから":-3752,"十二月":-2287};
- this.TW4__ = {"いう.":8576,"いう。":8576,"からな":-2348,"してい":2958,"たが,":1516,"たが、":1516,"ている":1538,"という":1349,"ました":5543,"ません":1097,"ようと":-4258,"よると":5865};
- this.UC1__ = {"A":484,"K":93,"M":645,"O":-505};
- this.UC2__ = {"A":819,"H":1059,"I":409,"M":3987,"N":5775,"O":646};
- this.UC3__ = {"A":-1370,"I":2311};
- this.UC4__ = {"A":-2643,"H":1809,"I":-1032,"K":-3450,"M":3565,"N":3876,"O":6646};
- this.UC5__ = {"H":313,"I":-1238,"K":-799,"M":539,"O":-831};
- this.UC6__ = {"H":-506,"I":-253,"K":87,"M":247,"O":-387};
- this.UP1__ = {"O":-214};
- this.UP2__ = {"B":69,"O":935};
- this.UP3__ = {"B":189};
- this.UQ1__ = {"BH":21,"BI":-12,"BK":-99,"BN":142,"BO":-56,"OH":-95,"OI":477,"OK":410,"OO":-2422};
- this.UQ2__ = {"BH":216,"BI":113,"OK":1759};
- this.UQ3__ = {"BA":-479,"BH":42,"BI":1913,"BK":-7198,"BM":3160,"BN":6427,"BO":14761,"OI":-827,"ON":-3212};
- this.UW1__ = {",":156,"、":156,"「":-463,"あ":-941,"う":-127,"が":-553,"き":121,"こ":505,"で":-201,"と":-547,"ど":-123,"に":-789,"の":-185,"は":-847,"も":-466,"や":-470,"よ":182,"ら":-292,"り":208,"れ":169,"を":-446,"ん":-137,"・":-135,"主":-402,"京":-268,"区":-912,"午":871,"国":-460,"大":561,"委":729,"市":-411,"日":-141,"理":361,"生":-408,"県":-386,"都":-718,"「":-463,"・":-135};
- this.UW2__ = {",":-829,"、":-829,"〇":892,"「":-645,"」":3145,"あ":-538,"い":505,"う":134,"お":-502,"か":1454,"が":-856,"く":-412,"こ":1141,"さ":878,"ざ":540,"し":1529,"す":-675,"せ":300,"そ":-1011,"た":188,"だ":1837,"つ":-949,"て":-291,"で":-268,"と":-981,"ど":1273,"な":1063,"に":-1764,"の":130,"は":-409,"ひ":-1273,"べ":1261,"ま":600,"も":-1263,"や":-402,"よ":1639,"り":-579,"る":-694,"れ":571,"を":-2516,"ん":2095,"ア":-587,"カ":306,"キ":568,"ッ":831,"三":-758,"不":-2150,"世":-302,"中":-968,"主":-861,"事":492,"人":-123,"会":978,"保":362,"入":548,"初":-3025,"副":-1566,"北":-3414,"区":-422,"大":-1769,"天":-865,"太":-483,"子":-1519,"学":760,"実":1023,"小":-2009,"市":-813,"年":-1060,"強":1067,"手":-1519,"揺":-1033,"政":1522,"文":-1355,"新":-1682,"日":-1815,"明":-1462,"最":-630,"朝":-1843,"本":-1650,"東":-931,"果":-665,"次":-2378,"民":-180,"気":-1740,"理":752,"発":529,"目":-1584,"相":-242,"県":-1165,"立":-763,"第":810,"米":509,"自":-1353,"行":838,"西":-744,"見":-3874,"調":1010,"議":1198,"込":3041,"開":1758,"間":-1257,"「":-645,"」":3145,"ッ":831,"ア":-587,"カ":306,"キ":568};
- this.UW3__ = {",":4889,"1":-800,"−":-1723,"、":4889,"々":-2311,"〇":5827,"」":2670,"〓":-3573,"あ":-2696,"い":1006,"う":2342,"え":1983,"お":-4864,"か":-1163,"が":3271,"く":1004,"け":388,"げ":401,"こ":-3552,"ご":-3116,"さ":-1058,"し":-395,"す":584,"せ":3685,"そ":-5228,"た":842,"ち":-521,"っ":-1444,"つ":-1081,"て":6167,"で":2318,"と":1691,"ど":-899,"な":-2788,"に":2745,"の":4056,"は":4555,"ひ":-2171,"ふ":-1798,"へ":1199,"ほ":-5516,"ま":-4384,"み":-120,"め":1205,"も":2323,"や":-788,"よ":-202,"ら":727,"り":649,"る":5905,"れ":2773,"わ":-1207,"を":6620,"ん":-518,"ア":551,"グ":1319,"ス":874,"ッ":-1350,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278,"・":-3794,"一":-1619,"下":-1759,"世":-2087,"両":3815,"中":653,"主":-758,"予":-1193,"二":974,"人":2742,"今":792,"他":1889,"以":-1368,"低":811,"何":4265,"作":-361,"保":-2439,"元":4858,"党":3593,"全":1574,"公":-3030,"六":755,"共":-1880,"円":5807,"再":3095,"分":457,"初":2475,"別":1129,"前":2286,"副":4437,"力":365,"動":-949,"務":-1872,"化":1327,"北":-1038,"区":4646,"千":-2309,"午":-783,"協":-1006,"口":483,"右":1233,"各":3588,"合":-241,"同":3906,"和":-837,"員":4513,"国":642,"型":1389,"場":1219,"外":-241,"妻":2016,"学":-1356,"安":-423,"実":-1008,"家":1078,"小":-513,"少":-3102,"州":1155,"市":3197,"平":-1804,"年":2416,"広":-1030,"府":1605,"度":1452,"建":-2352,"当":-3885,"得":1905,"思":-1291,"性":1822,"戸":-488,"指":-3973,"政":-2013,"教":-1479,"数":3222,"文":-1489,"新":1764,"日":2099,"旧":5792,"昨":-661,"時":-1248,"曜":-951,"最":-937,"月":4125,"期":360,"李":3094,"村":364,"東":-805,"核":5156,"森":2438,"業":484,"氏":2613,"民":-1694,"決":-1073,"法":1868,"海":-495,"無":979,"物":461,"特":-3850,"生":-273,"用":914,"町":1215,"的":7313,"直":-1835,"省":792,"県":6293,"知":-1528,"私":4231,"税":401,"立":-960,"第":1201,"米":7767,"系":3066,"約":3663,"級":1384,"統":-4229,"総":1163,"線":1255,"者":6457,"能":725,"自":-2869,"英":785,"見":1044,"調":-562,"財":-733,"費":1777,"車":1835,"軍":1375,"込":-1504,"通":-1136,"選":-681,"郎":1026,"郡":4404,"部":1200,"金":2163,"長":421,"開":-1432,"間":1302,"関":-1282,"雨":2009,"電":-1045,"非":2066,"駅":1620,"1":-800,"」":2670,"・":-3794,"ッ":-1350,"ア":551,"グ":1319,"ス":874,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278};
- this.UW4__ = {",":3930,".":3508,"―":-4841,"、":3930,"。":3508,"〇":4999,"「":1895,"」":3798,"〓":-5156,"あ":4752,"い":-3435,"う":-640,"え":-2514,"お":2405,"か":530,"が":6006,"き":-4482,"ぎ":-3821,"く":-3788,"け":-4376,"げ":-4734,"こ":2255,"ご":1979,"さ":2864,"し":-843,"じ":-2506,"す":-731,"ず":1251,"せ":181,"そ":4091,"た":5034,"だ":5408,"ち":-3654,"っ":-5882,"つ":-1659,"て":3994,"で":7410,"と":4547,"な":5433,"に":6499,"ぬ":1853,"ね":1413,"の":7396,"は":8578,"ば":1940,"ひ":4249,"び":-4134,"ふ":1345,"へ":6665,"べ":-744,"ほ":1464,"ま":1051,"み":-2082,"む":-882,"め":-5046,"も":4169,"ゃ":-2666,"や":2795,"ょ":-1544,"よ":3351,"ら":-2922,"り":-9726,"る":-14896,"れ":-2613,"ろ":-4570,"わ":-1783,"を":13150,"ん":-2352,"カ":2145,"コ":1789,"セ":1287,"ッ":-724,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637,"・":-4371,"ー":-11870,"一":-2069,"中":2210,"予":782,"事":-190,"井":-1768,"人":1036,"以":544,"会":950,"体":-1286,"作":530,"側":4292,"先":601,"党":-2006,"共":-1212,"内":584,"円":788,"初":1347,"前":1623,"副":3879,"力":-302,"動":-740,"務":-2715,"化":776,"区":4517,"協":1013,"参":1555,"合":-1834,"和":-681,"員":-910,"器":-851,"回":1500,"国":-619,"園":-1200,"地":866,"場":-1410,"塁":-2094,"士":-1413,"多":1067,"大":571,"子":-4802,"学":-1397,"定":-1057,"寺":-809,"小":1910,"屋":-1328,"山":-1500,"島":-2056,"川":-2667,"市":2771,"年":374,"庁":-4556,"後":456,"性":553,"感":916,"所":-1566,"支":856,"改":787,"政":2182,"教":704,"文":522,"方":-856,"日":1798,"時":1829,"最":845,"月":-9066,"木":-485,"来":-442,"校":-360,"業":-1043,"氏":5388,"民":-2716,"気":-910,"沢":-939,"済":-543,"物":-735,"率":672,"球":-1267,"生":-1286,"産":-1101,"田":-2900,"町":1826,"的":2586,"目":922,"省":-3485,"県":2997,"空":-867,"立":-2112,"第":788,"米":2937,"系":786,"約":2171,"経":1146,"統":-1169,"総":940,"線":-994,"署":749,"者":2145,"能":-730,"般":-852,"行":-792,"規":792,"警":-1184,"議":-244,"谷":-1000,"賞":730,"車":-1481,"軍":1158,"輪":-1433,"込":-3370,"近":929,"道":-1291,"選":2596,"郎":-4866,"都":1192,"野":-1100,"銀":-2213,"長":357,"間":-2344,"院":-2297,"際":-2604,"電":-878,"領":-1659,"題":-792,"館":-1984,"首":1749,"高":2120,"「":1895,"」":3798,"・":-4371,"ッ":-724,"ー":-11870,"カ":2145,"コ":1789,"セ":1287,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637};
- this.UW5__ = {",":465,".":-299,"1":-514,"E2":-32768,"]":-2762,"、":465,"。":-299,"「":363,"あ":1655,"い":331,"う":-503,"え":1199,"お":527,"か":647,"が":-421,"き":1624,"ぎ":1971,"く":312,"げ":-983,"さ":-1537,"し":-1371,"す":-852,"だ":-1186,"ち":1093,"っ":52,"つ":921,"て":-18,"で":-850,"と":-127,"ど":1682,"な":-787,"に":-1224,"の":-635,"は":-578,"べ":1001,"み":502,"め":865,"ゃ":3350,"ょ":854,"り":-208,"る":429,"れ":504,"わ":419,"を":-1264,"ん":327,"イ":241,"ル":451,"ン":-343,"中":-871,"京":722,"会":-1153,"党":-654,"務":3519,"区":-901,"告":848,"員":2104,"大":-1296,"学":-548,"定":1785,"嵐":-1304,"市":-2991,"席":921,"年":1763,"思":872,"所":-814,"挙":1618,"新":-1682,"日":218,"月":-4353,"査":932,"格":1356,"機":-1508,"氏":-1347,"田":240,"町":-3912,"的":-3149,"相":1319,"省":-1052,"県":-4003,"研":-997,"社":-278,"空":-813,"統":1955,"者":-2233,"表":663,"語":-1073,"議":1219,"選":-1018,"郎":-368,"長":786,"間":1191,"題":2368,"館":-689,"1":-514,"E2":-32768,"「":363,"イ":241,"ル":451,"ン":-343};
- this.UW6__ = {",":227,".":808,"1":-270,"E1":306,"、":227,"。":808,"あ":-307,"う":189,"か":241,"が":-73,"く":-121,"こ":-200,"じ":1782,"す":383,"た":-428,"っ":573,"て":-1014,"で":101,"と":-105,"な":-253,"に":-149,"の":-417,"は":-236,"も":-206,"り":187,"る":-135,"を":195,"ル":-673,"ン":-496,"一":-277,"中":201,"件":-800,"会":624,"前":302,"区":1792,"員":-1212,"委":798,"学":-960,"市":887,"広":-695,"後":535,"業":-697,"相":753,"社":-507,"福":974,"空":-822,"者":1811,"連":463,"郎":1082,"1":-270,"E1":306,"ル":-673,"ン":-496};
-
- return this;
- }
- TinySegmenter.prototype.ctype_ = function(str) {
- for (var i in this.chartype_) {
- if (str.match(this.chartype_[i][0])) {
- return this.chartype_[i][1];
- }
- }
- return "O";
- }
-
- TinySegmenter.prototype.ts_ = function(v) {
- if (v) { return v; }
- return 0;
- }
-
- TinySegmenter.prototype.segment = function(input) {
- if (input == null || input == undefined || input == "") {
- return [];
- }
- var result = [];
- var seg = ["B3","B2","B1"];
- var ctype = ["O","O","O"];
- var o = input.split("");
- for (i = 0; i < o.length; ++i) {
- seg.push(o[i]);
- ctype.push(this.ctype_(o[i]))
- }
- seg.push("E1");
- seg.push("E2");
- seg.push("E3");
- ctype.push("O");
- ctype.push("O");
- ctype.push("O");
- var word = seg[3];
- var p1 = "U";
- var p2 = "U";
- var p3 = "U";
- for (var i = 4; i < seg.length - 3; ++i) {
- var score = this.BIAS__;
- var w1 = seg[i-3];
- var w2 = seg[i-2];
- var w3 = seg[i-1];
- var w4 = seg[i];
- var w5 = seg[i+1];
- var w6 = seg[i+2];
- var c1 = ctype[i-3];
- var c2 = ctype[i-2];
- var c3 = ctype[i-1];
- var c4 = ctype[i];
- var c5 = ctype[i+1];
- var c6 = ctype[i+2];
- score += this.ts_(this.UP1__[p1]);
- score += this.ts_(this.UP2__[p2]);
- score += this.ts_(this.UP3__[p3]);
- score += this.ts_(this.BP1__[p1 + p2]);
- score += this.ts_(this.BP2__[p2 + p3]);
- score += this.ts_(this.UW1__[w1]);
- score += this.ts_(this.UW2__[w2]);
- score += this.ts_(this.UW3__[w3]);
- score += this.ts_(this.UW4__[w4]);
- score += this.ts_(this.UW5__[w5]);
- score += this.ts_(this.UW6__[w6]);
- score += this.ts_(this.BW1__[w2 + w3]);
- score += this.ts_(this.BW2__[w3 + w4]);
- score += this.ts_(this.BW3__[w4 + w5]);
- score += this.ts_(this.TW1__[w1 + w2 + w3]);
- score += this.ts_(this.TW2__[w2 + w3 + w4]);
- score += this.ts_(this.TW3__[w3 + w4 + w5]);
- score += this.ts_(this.TW4__[w4 + w5 + w6]);
- score += this.ts_(this.UC1__[c1]);
- score += this.ts_(this.UC2__[c2]);
- score += this.ts_(this.UC3__[c3]);
- score += this.ts_(this.UC4__[c4]);
- score += this.ts_(this.UC5__[c5]);
- score += this.ts_(this.UC6__[c6]);
- score += this.ts_(this.BC1__[c2 + c3]);
- score += this.ts_(this.BC2__[c3 + c4]);
- score += this.ts_(this.BC3__[c4 + c5]);
- score += this.ts_(this.TC1__[c1 + c2 + c3]);
- score += this.ts_(this.TC2__[c2 + c3 + c4]);
- score += this.ts_(this.TC3__[c3 + c4 + c5]);
- score += this.ts_(this.TC4__[c4 + c5 + c6]);
- // score += this.ts_(this.TC5__[c4 + c5 + c6]);
- score += this.ts_(this.UQ1__[p1 + c1]);
- score += this.ts_(this.UQ2__[p2 + c2]);
- score += this.ts_(this.UQ3__[p3 + c3]);
- score += this.ts_(this.BQ1__[p2 + c2 + c3]);
- score += this.ts_(this.BQ2__[p2 + c3 + c4]);
- score += this.ts_(this.BQ3__[p3 + c2 + c3]);
- score += this.ts_(this.BQ4__[p3 + c3 + c4]);
- score += this.ts_(this.TQ1__[p2 + c1 + c2 + c3]);
- score += this.ts_(this.TQ2__[p2 + c2 + c3 + c4]);
- score += this.ts_(this.TQ3__[p3 + c1 + c2 + c3]);
- score += this.ts_(this.TQ4__[p3 + c2 + c3 + c4]);
- var p = "O";
- if (score > 0) {
- result.push(word);
- word = "";
- p = "B";
- }
- p1 = p2;
- p2 = p3;
- p3 = p;
- word += seg[i];
- }
- result.push(word);
-
- return result;
- }
-
- lunr.TinySegmenter = TinySegmenter;
- };
-
-})); \ No newline at end of file