/** * lunr - http://lunrjs.com - a bit like solr, but much smaller and not as bright - 0.7.1 * copyright (c) 2016 oliver nightingale * @license mit */ !function(){var e=function(t){var n=new e.index;return n.pipeline.add(e.trimmer,e.stopwordfilter,e.stemmer),t&&t.call(n,n),n};e.version="0.7.1",e.utils={},e.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),e.utils.asstring=function(e){return void 0===e||null===e?"":e.tostring()},e.eventemitter=function(){this.events={}},e.eventemitter.prototype.addlistener=function(){var e=array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new typeerror("last argument must be a function");n.foreach(function(e){this.hashandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},e.eventemitter.prototype.removelistener=function(e,t){if(this.hashandler(e)){var n=this.events[e].indexof(t);this.events[e].splice(n,1),this.events[e].length||delete this.events[e]}},e.eventemitter.prototype.emit=function(e){if(this.hashandler(e)){var t=array.prototype.slice.call(arguments,1);this.events[e].foreach(function(e){e.apply(void 0,t)})}},e.eventemitter.prototype.hashandler=function(e){return e in this.events},"undefined"!=typeof module&&module.exports&&(nodejieba_segment=require("nodejieba")),e.tokenizer=function(t){if(!arguments.length||null==t||void 0==t)return[];if(array.isarray(t))return t.map(function(t){return e.utils.asstring(t).tolowercase()});var n=t.tostring().trim().tolowercase();return"undefined"!=typeof nodejieba_segment?nodejieba_segment.cut(n,true):n.split(e.tokenizer.seperator)},e.tokenizer.seperator=/[\s\-]+/,e.tokenizer.load=function(e){var t=this.registeredfunctions[e];if(!t)throw new error("cannot load un-registered function: "+e);return t},e.tokenizer.label="default",e.tokenizer.registeredfunctions={"default":e.tokenizer},e.tokenizer.registerfunction=function(t,n){n in this.registeredfunctions&&e.utils.warn("overwriting existing tokenizer: "+n),t.label=n,this.registeredfunctions[n]=t},e.pipeline=function(){this._stack=[]},e.pipeline.registeredfunctions={},e.pipeline.registerfunction=function(t,n){n in this.registeredfunctions&&e.utils.warn("overwriting existing registered function: "+n),t.label=n,e.pipeline.registeredfunctions[t.label]=t},e.pipeline.warniffunctionnotregistered=function(t){var n=t.label&&t.label in this.registeredfunctions;n||e.utils.warn("function is not registered with pipeline. this may cause problems when serialising the index.\n",t)},e.pipeline.load=function(t){var n=new e.pipeline;return t.foreach(function(t){var i=e.pipeline.registeredfunctions[t];if(!i)throw new error("cannot load un-registered function: "+t);n.add(i)}),n},e.pipeline.prototype.add=function(){var t=array.prototype.slice.call(arguments);t.foreach(function(t){e.pipeline.warniffunctionnotregistered(t),this._stack.push(t)},this)},e.pipeline.prototype.after=function(t,n){e.pipeline.warniffunctionnotregistered(n);var i=this._stack.indexof(t);if(-1==i)throw new error("cannot find existingfn");i+=1,this._stack.splice(i,0,n)},e.pipeline.prototype.before=function(t,n){e.pipeline.warniffunctionnotregistered(n);var i=this._stack.indexof(t);if(-1==i)throw new error("cannot find existingfn");this._stack.splice(i,0,n)},e.pipeline.prototype.remove=function(e){var t=this._stack.indexof(e);-1!=t&&this._stack.splice(t,1)},e.pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._stack.length,r=0;n>r;r++){for(var o=e[r],s=0;i>s&&(o=this._stack[s](o,r,e),void 0!==o&&""!==o);s++);void 0!==o&&""!==o&&t.push(o)}return t},e.pipeline.prototype.reset=function(){this._stack=[]},e.pipeline.prototype.tojson=function(){return this._stack.map(function(t){return e.pipeline.warniffunctionnotregistered(t),t.label})},e.vector=function(){this._magnitude=null,this.list=void 0,this.length=0},e.vector.node=function(e,t,n){this.idx=e,this.val=t,this.next=n},e.vector.prototype.insert=function(t,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new e.vector.node(t,n,i),this.length++;if(tn.idx?n=n.next:(i+=t.val*n.val,t=t.next,n=n.next);return i},e.vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},e.sortedset=function(){this.length=0,this.elements=[]},e.sortedset.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},e.sortedset.prototype.add=function(){var e,t;for(e=0;e1;){if(o===e)return r;e>o&&(t=r),o>e&&(n=r),i=n-t,r=t+math.floor(i/2),o=this.elements[r]}return o===e?r:-1},e.sortedset.prototype.locationfor=function(e){for(var t=0,n=this.elements.length,i=n-t,r=t+math.floor(i/2),o=this.elements[r];i>1;)e>o&&(t=r),o>e&&(n=r),i=n-t,r=t+math.floor(i/2),o=this.elements[r];return o>e?r:e>o?r+1:void 0},e.sortedset.prototype.intersect=function(t){for(var n=new e.sortedset,i=0,r=0,o=this.length,s=t.length,a=this.elements,h=t.elements;;){if(i>o-1||r>s-1)break;a[i]!==h[r]?a[i]h[r]&&r++:(n.add(a[i]),i++,r++)}return n},e.sortedset.prototype.clone=function(){var t=new e.sortedset;return t.elements=this.toarray(),t.length=t.elements.length,t},e.sortedset.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var r=0,o=n.toarray();rp;p++)c[p]===a&&f++;h+=f/d*l.boost}}this.tokenstore.add(a,{ref:o,tf:h})}n&&this.eventemitter.emit("add",t,this)},e.index.prototype.remove=function(e,t){var n=e[this._ref],t=void 0===t?!0:t;if(this.documentstore.has(n)){var i=this.documentstore.get(n);this.documentstore.remove(n),i.foreach(function(e){this.tokenstore.remove(e,n)},this),t&&this.eventemitter.emit("remove",e,this)}},e.index.prototype.update=function(e,t){var t=void 0===t?!0:t;this.remove(e,!1),this.add(e,!1),t&&this.eventemitter.emit("update",e,this)},e.index.prototype.idf=function(e){var t="@"+e;if(object.prototype.hasownproperty.call(this._idfcache,t))return this._idfcache[t];var n=this.tokenstore.count(e),i=1;return n>0&&(i=1+math.log(this.documentstore.length/n)),this._idfcache[t]=i},e.index.prototype.search=function(t){var n=this.pipeline.run(this.tokenizerfn(t)),i=new e.vector,r=[],o=this._fields.reduce(function(e,t){return e+t.boost},0),s=n.some(function(e){return this.tokenstore.has(e)},this);if(!s)return[];n.foreach(function(t,n,s){var a=1/s.length*this._fields.length*o,h=this,u=this.tokenstore.expand(t).reduce(function(n,r){var o=h.corpustokens.indexof(r),s=h.idf(r),u=1,l=new e.sortedset;if(r!==t){var c=math.max(3,r.length-t.length);u=1/math.log(c)}o>-1&&i.insert(o,a*s*u);for(var d=h.tokenstore.get(r),f=object.keys(d),p=f.length,v=0;p>v;v++)l.add(d[f[v]].ref);return n.union(l)},new e.sortedset);r.push(u)},this);var a=r.reduce(function(e,t){return e.intersect(t)});return a.map(function(e){return{ref:e,score:i.similarity(this.documentvector(e))}},this).sort(function(e,t){return t.score-e.score})},e.index.prototype.documentvector=function(t){for(var n=this.documentstore.get(t),i=n.length,r=new e.vector,o=0;i>o;o++){var s=n.elements[o],a=this.tokenstore.get(s)[t].tf,h=this.idf(s);r.insert(this.corpustokens.indexof(s),a*h)}return r},e.index.prototype.tojson=function(){return{version:e.version,fields:this._fields,ref:this._ref,tokenizer:this.tokenizerfn.label,documentstore:this.documentstore.tojson(),tokenstore:this.tokenstore.tojson(),corpustokens:this.corpustokens.tojson(),pipeline:this.pipeline.tojson()}},e.index.prototype.use=function(e){var t=array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},e.store=function(){this.store={},this.length=0},e.store.load=function(t){var n=new this;return n.length=t.length,n.store=object.keys(t.store).reduce(function(n,i){return n[i]=e.sortedset.load(t.store[i]),n},{}),n},e.store.prototype.set=function(e,t){this.has(e)||this.length++,this.store[e]=t},e.store.prototype.get=function(e){return this.store[e]},e.store.prototype.has=function(e){return e in this.store},e.store.prototype.remove=function(e){this.has(e)&&(delete this.store[e],this.length--)},e.store.prototype.tojson=function(){return{store:this.store,length:this.length}},e.stemmer=function(){var e={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"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",r=n+"[^aeiouy]*",o=i+"[aeiou]*",s="^("+r+")?"+o+r,a="^("+r+")?"+o+r+"("+o+")?$",h="^("+r+")?"+o+r+o+r,u="^("+r+")?"+i,l=new regexp(s),c=new regexp(h),d=new regexp(a),f=new regexp(u),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,s=/(at|bl|iz)$/,w=new regexp("([^aeiouylsz])\\1$"),k=new regexp("^"+r+i+"[^aeiouwxy]$"),x=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,e=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,f=/^(.+?)(s|t)(ion)$/,z=/^(.+?)e$/,o=/ll$/,p=new regexp("^"+r+i+"[^aeiouwxy]$"),t=function(n){var i,r,o,s,a,h,u;if(n.length<3)return n;if(o=n.substr(0,1),"y"==o&&(n=o.touppercase()+n.substr(1)),s=p,a=v,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=g,a=m,s.test(n)){var t=s.exec(n);s=l,s.test(t[1])&&(s=y,n=n.replace(s,""))}else if(a.test(n)){var t=a.exec(n);i=t[1],a=f,a.test(i)&&(n=i,a=s,h=w,u=k,a.test(n)?n+="e":h.test(n)?(s=y,n=n.replace(s,"")):u.test(n)&&(n+="e"))}if(s=x,s.test(n)){var t=s.exec(n);i=t[1],n=i+"i"}if(s=b,s.test(n)){var t=s.exec(n);i=t[1],r=t[2],s=l,s.test(i)&&(n=i+e[r])}if(s=e,s.test(n)){var t=s.exec(n);i=t[1],r=t[2],s=l,s.test(i)&&(n=i+t[r])}if(s=_,a=f,s.test(n)){var t=s.exec(n);i=t[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var t=a.exec(n);i=t[1]+t[2],a=c,a.test(i)&&(n=i)}if(s=z,s.test(n)){var t=s.exec(n);i=t[1],s=c,a=d,h=p,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=o,a=c,s.test(n)&&a.test(n)&&(s=y,n=n.replace(s,"")),"y"==o&&(n=o.tolowercase()+n.substr(1)),n};return t}(),e.pipeline.registerfunction(e.stemmer,"stemmer"),e.generatestopwordfilter=function(e){var t=e.reduce(function(e,t){return e[t]=t,e},{});return function(e){return e&&t[e]!==e?e:void 0}},e.stopwordfilter=e.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"]),e.pipeline.registerfunction(e.stopwordfilter,"stopwordfilter"),e.trimmer=function(e){var t=e.replace(/^\s+/,"").replace(/\s+$/,"");return""===t?void 0:t},e.pipeline.registerfunction(e.trimmer,"trimmer"),e.tokenstore=function(){this.root={docs:{}},this.length=0},e.tokenstore.load=function(e){var t=new this;return t.root=e.root,t.length=e.length,t},e.tokenstore.prototype.add=function(e,t,n){var n=n||this.root,i=e.charat(0),r=e.slice(1);return i in n||(n[i]={docs:{}}),0===r.length?(n[i].docs[t.ref]=t,void(this.length+=1)):this.add(r,t,n[i])},e.tokenstore.prototype.has=function(e){if(!e)return!1;for(var t=this.root,n=0;n