-
Notifications
You must be signed in to change notification settings - Fork 0
/
lunr.min-f2458d08.js
1 lines (1 loc) · 28 KB
/
lunr.min-f2458d08.js
1
!function(){var t,l,c,e,r,h,d,f,p,y,m,g,x,v,w,Q,k,S,L,E,T,b,P,I,O,i,n,s,V=function(e){var t=new V.Builder;return t.pipeline.add(V.trimmer,V.stopWordFilter,V.stemmer),t.searchPipeline.add(V.stemmer),e.call(t,t),t.build()};V.version="2.2.0",V.utils={},V.utils.warn=(t=this,function(e){t.console&&console.warn&&console.warn(e)}),V.utils.asString=function(e){return null==e?"":e.toString()},V.utils.clone=function(e){if(null==e)return e;for(var t=Object.create(null),r=Object.keys(e),i=0;i<r.length;i++){var n=r[i],s=e[n];if(Array.isArray(s))t[n]=s.slice();else{if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s)throw new TypeError("clone is not deep and does not support nested objects");t[n]=s}}return t},V.FieldRef=function(e,t,r){this.docRef=e,this.fieldName=t,this._stringValue=r},V.FieldRef.joiner="/",V.FieldRef.fromString=function(e){var t=e.indexOf(V.FieldRef.joiner);if(-1===t)throw"malformed field ref string";var r=e.slice(0,t),i=e.slice(t+1);return new V.FieldRef(i,r,e)},V.FieldRef.prototype.toString=function(){return null==this._stringValue&&(this._stringValue=this.fieldName+V.FieldRef.joiner+this.docRef),this._stringValue},V.Set=function(e){if(this.elements=Object.create(null),e){this.length=e.length;for(var t=0;t<this.length;t++)this.elements[e[t]]=!0}else this.length=0},V.Set.complete={intersect:function(e){return e},union:function(e){return e},contains:function(){return!0}},V.Set.empty={intersect:function(){return this},union:function(e){return e},contains:function(){return!1}},V.Set.prototype.contains=function(e){return!!this.elements[e]},V.Set.prototype.intersect=function(e){var t,r,i,n=[];this.length<e.length?(t=this,r=e):(t=e,r=this),i=Object.keys(t.elements);for(var s=0;s<i.length;s++){var o=i[s];o in r.elements&&n.push(o)}return new V.Set(n)},V.Set.prototype.union=function(e){return new V.Set(Object.keys(this.elements).concat(Object.keys(e.elements)))},V.idf=function(e,t){var r=0;for(var i in e)"_index"!=i&&(r+=Object.keys(e[i]).length);var n=(t-r+.5)/(r+.5);return Math.log(1+Math.abs(n))},V.Token=function(e,t){this.str=e||"",this.metadata=t||{}},V.Token.prototype.toString=function(){return this.str},V.Token.prototype.update=function(e){return this.str=e(this.str,this.metadata),this},V.Token.prototype.clone=function(e){return e=e||function(e){return e},new V.Token(e(this.str,this.metadata),this.metadata)},V.tokenizer=function(e,t){if(null==e||null==e)return[];if(Array.isArray(e))return e.map(function(e){return new V.Token(V.utils.asString(e).toLowerCase(),V.utils.clone(t))});for(var r=e.toString().trim().toLowerCase(),i=r.length,n=[],s=0,o=0;s<=i;s++){var a=s-o;if(r.charAt(s).match(V.tokenizer.separator)||s==i){if(0<a){var u=V.utils.clone(t)||{};u.position=[o,a],u.index=n.length,n.push(new V.Token(r.slice(o,s),u))}o=s+1}}return n},V.tokenizer.separator=/[\s\-]+/,V.Pipeline=function(){this._stack=[]},V.Pipeline.registeredFunctions=Object.create(null),V.Pipeline.registerFunction=function(e,t){t in this.registeredFunctions&&V.utils.warn("Overwriting existing registered function: "+t),e.label=t,V.Pipeline.registeredFunctions[e.label]=e},V.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||V.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},V.Pipeline.load=function(e){var r=new V.Pipeline;return e.forEach(function(e){var t=V.Pipeline.registeredFunctions[e];if(!t)throw new Error("Cannot load unregistered function: "+e);r.add(t)}),r},V.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){V.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},V.Pipeline.prototype.after=function(e,t){V.Pipeline.warnIfFunctionNotRegistered(t);var r=this._stack.indexOf(e);if(-1==r)throw new Error("Cannot find existingFn");r+=1,this._stack.splice(r,0,t)},V.Pipeline.prototype.before=function(e,t){V.Pipeline.warnIfFunctionNotRegistered(t);var r=this._stack.indexOf(e);if(-1==r)throw new Error("Cannot find existingFn");this._stack.splice(r,0,t)},V.Pipeline.prototype.remove=function(e){var t=this._stack.indexOf(e);-1!=t&&this._stack.splice(t,1)},V.Pipeline.prototype.run=function(e){for(var t=this._stack.length,r=0;r<t;r++){for(var i=this._stack[r],n=[],s=0;s<e.length;s++){var o=i(e[s],s,e);if(void 0!==o&&""!==o)if(o instanceof Array)for(var a=0;a<o.length;a++)n.push(o[a]);else n.push(o)}e=n}return e},V.Pipeline.prototype.runString=function(e,t){var r=new V.Token(e,t);return this.run([r]).map(function(e){return e.toString()})},V.Pipeline.prototype.reset=function(){this._stack=[]},V.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return V.Pipeline.warnIfFunctionNotRegistered(e),e.label})},V.Vector=function(e){this._magnitude=0,this.elements=e||[]},V.Vector.prototype.positionForIndex=function(e){if(0==this.elements.length)return 0;for(var t=0,r=this.elements.length/2,i=r-t,n=Math.floor(i/2),s=this.elements[2*n];1<i&&(s<e&&(t=n),e<s&&(r=n),s!=e);)i=r-t,n=t+Math.floor(i/2),s=this.elements[2*n];return s==e?2*n:e<s?2*n:s<e?2*(n+1):void 0},V.Vector.prototype.insert=function(e,t){this.upsert(e,t,function(){throw"duplicate index"})},V.Vector.prototype.upsert=function(e,t,r){this._magnitude=0;var i=this.positionForIndex(e);this.elements[i]==e?this.elements[i+1]=r(this.elements[i+1],t):this.elements.splice(i,0,e,t)},V.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var e=0,t=this.elements.length,r=1;r<t;r+=2){var i=this.elements[r];e+=i*i}return this._magnitude=Math.sqrt(e)},V.Vector.prototype.dot=function(e){for(var t=0,r=this.elements,i=e.elements,n=r.length,s=i.length,o=0,a=0,u=0,l=0;u<n&&l<s;)(o=r[u])<(a=i[l])?u+=2:a<o?l+=2:o==a&&(t+=r[u+1]*i[l+1],u+=2,l+=2);return t},V.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())||0},V.Vector.prototype.toArray=function(){for(var e=new Array(this.elements.length/2),t=1,r=0;t<this.elements.length;t+=2,r++)e[r]=this.elements[t];return e},V.Vector.prototype.toJSON=function(){return this.elements},V.stemmer=(l={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"},c={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},e="[aeiouy]",r="[^aeiou][^aeiouy]*",h=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),d=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),f=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$"),p=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy]"),y=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,x=/^(.+?)(ed|ing)$/,v=/.$/,w=/(at|bl|iz)$/,Q=new RegExp("([^aeiouylsz])\\1$"),k=new RegExp("^"+r+e+"[^aeiouwxy]$"),S=/^(.+?[^aeiou])y$/,L=/^(.+?)(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)$/,T=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,b=/^(.+?)(s|t)(ion)$/,P=/^(.+?)e$/,I=/ll$/,O=new RegExp("^"+r+e+"[^aeiouwxy]$"),i=function(e){var t,r,i,n,s,o,a;if(e.length<3)return e;if("y"==(i=e.substr(0,1))&&(e=i.toUpperCase()+e.substr(1)),s=m,(n=y).test(e)?e=e.replace(n,"$1$2"):s.test(e)&&(e=e.replace(s,"$1$2")),s=x,(n=g).test(e)){var u=n.exec(e);(n=h).test(u[1])&&(n=v,e=e.replace(n,""))}else if(s.test(e)){t=(u=s.exec(e))[1],(s=p).test(t)&&(o=Q,a=k,(s=w).test(e=t)?e+="e":o.test(e)?(n=v,e=e.replace(n,"")):a.test(e)&&(e+="e"))}(n=S).test(e)&&(e=(t=(u=n.exec(e))[1])+"i");(n=L).test(e)&&(t=(u=n.exec(e))[1],r=u[2],(n=h).test(t)&&(e=t+l[r]));(n=E).test(e)&&(t=(u=n.exec(e))[1],r=u[2],(n=h).test(t)&&(e=t+c[r]));if(s=b,(n=T).test(e))t=(u=n.exec(e))[1],(n=d).test(t)&&(e=t);else if(s.test(e)){t=(u=s.exec(e))[1]+u[2],(s=d).test(t)&&(e=t)}(n=P).test(e)&&(t=(u=n.exec(e))[1],s=f,o=O,((n=d).test(t)||s.test(t)&&!o.test(t))&&(e=t));return s=d,(n=I).test(e)&&s.test(e)&&(n=v,e=e.replace(n,"")),"y"==i&&(e=i.toLowerCase()+e.substr(1)),e},function(e){return e.update(i)}),V.Pipeline.registerFunction(V.stemmer,"stemmer"),V.generateStopWordFilter=function(e){var t=e.reduce(function(e,t){return e[t]=t,e},{});return function(e){if(e&&t[e.toString()]!==e.toString())return e}},V.stopWordFilter=V.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"]),V.Pipeline.registerFunction(V.stopWordFilter,"stopWordFilter"),V.trimmer=function(e){return e.update(function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")})},V.Pipeline.registerFunction(V.trimmer,"trimmer"),V.TokenSet=function(){this.final=!1,this.edges={},this.id=V.TokenSet._nextId,V.TokenSet._nextId+=1},V.TokenSet._nextId=1,V.TokenSet.fromArray=function(e){for(var t=new V.TokenSet.Builder,r=0,i=e.length;r<i;r++)t.insert(e[r]);return t.finish(),t.root},V.TokenSet.fromClause=function(e){return"editDistance"in e?V.TokenSet.fromFuzzyString(e.term,e.editDistance):V.TokenSet.fromString(e.term)},V.TokenSet.fromFuzzyString=function(e,t){for(var r=new V.TokenSet,i=[{node:r,editsRemaining:t,str:e}];i.length;){var n,s,o,a=i.pop();if(0<a.str.length)(s=a.str.charAt(0))in a.node.edges?n=a.node.edges[s]:(n=new V.TokenSet,a.node.edges[s]=n),1==a.str.length?n.final=!0:i.push({node:n,editsRemaining:a.editsRemaining,str:a.str.slice(1)});if(0<a.editsRemaining&&1<a.str.length)(s=a.str.charAt(1))in a.node.edges?o=a.node.edges[s]:(o=new V.TokenSet,a.node.edges[s]=o),a.str.length<=2?o.final=!0:i.push({node:o,editsRemaining:a.editsRemaining-1,str:a.str.slice(2)});if(0<a.editsRemaining&&1==a.str.length&&(a.node.final=!0),0<a.editsRemaining&&1<=a.str.length){if("*"in a.node.edges)var u=a.node.edges["*"];else{u=new V.TokenSet;a.node.edges["*"]=u}1==a.str.length?u.final=!0:i.push({node:u,editsRemaining:a.editsRemaining-1,str:a.str.slice(1)})}if(0<a.editsRemaining){if("*"in a.node.edges)var l=a.node.edges["*"];else{l=new V.TokenSet;a.node.edges["*"]=l}0==a.str.length?l.final=!0:i.push({node:l,editsRemaining:a.editsRemaining-1,str:a.str})}if(0<a.editsRemaining&&1<a.str.length){var c,h=a.str.charAt(0),d=a.str.charAt(1);d in a.node.edges?c=a.node.edges[d]:(c=new V.TokenSet,a.node.edges[d]=c),1==a.str.length?c.final=!0:i.push({node:c,editsRemaining:a.editsRemaining-1,str:h+a.str.slice(2)})}}return r},V.TokenSet.fromString=function(e){for(var t=new V.TokenSet,r=t,i=!1,n=0,s=e.length;n<s;n++){var o=e[n],a=n==s-1;if("*"==o)i=!0,(t.edges[o]=t).final=a;else{var u=new V.TokenSet;u.final=a,t.edges[o]=u,t=u,i&&(t.edges["*"]=r)}}return r},V.TokenSet.prototype.toArray=function(){for(var e=[],t=[{prefix:"",node:this}];t.length;){var r=t.pop(),i=Object.keys(r.node.edges),n=i.length;r.node.final&&e.push(r.prefix);for(var s=0;s<n;s++){var o=i[s];t.push({prefix:r.prefix.concat(o),node:r.node.edges[o]})}}return e},V.TokenSet.prototype.toString=function(){if(this._str)return this._str;for(var e=this.final?"1":"0",t=Object.keys(this.edges).sort(),r=t.length,i=0;i<r;i++){var n=t[i];e=e+n+this.edges[n].id}return e},V.TokenSet.prototype.intersect=function(e){for(var t=new V.TokenSet,r=void 0,i=[{qNode:e,output:t,node:this}];i.length;){r=i.pop();for(var n=Object.keys(r.qNode.edges),s=n.length,o=Object.keys(r.node.edges),a=o.length,u=0;u<s;u++)for(var l=n[u],c=0;c<a;c++){var h=o[c];if(h==l||"*"==l){var d=r.node.edges[h],f=r.qNode.edges[l],p=d.final&&f.final,y=void 0;h in r.output.edges?(y=r.output.edges[h]).final=y.final||p:((y=new V.TokenSet).final=p,r.output.edges[h]=y),i.push({qNode:f,output:y,node:d})}}}return t},V.TokenSet.Builder=function(){this.previousWord="",this.root=new V.TokenSet,this.uncheckedNodes=[],this.minimizedNodes={}},V.TokenSet.Builder.prototype.insert=function(e){var t,r=0;if(e<this.previousWord)throw new Error("Out of order word insertion");for(var i=0;i<e.length&&i<this.previousWord.length&&e[i]==this.previousWord[i];i++)r++;this.minimize(r),t=0==this.uncheckedNodes.length?this.root:this.uncheckedNodes[this.uncheckedNodes.length-1].child;for(i=r;i<e.length;i++){var n=new V.TokenSet,s=e[i];t.edges[s]=n,this.uncheckedNodes.push({parent:t,char:s,child:n}),t=n}t.final=!0,this.previousWord=e},V.TokenSet.Builder.prototype.finish=function(){this.minimize(0)},V.TokenSet.Builder.prototype.minimize=function(e){for(var t=this.uncheckedNodes.length-1;e<=t;t--){var r=this.uncheckedNodes[t],i=r.child.toString();i in this.minimizedNodes?r.parent.edges[r.char]=this.minimizedNodes[i]:(r.child._str=i,this.minimizedNodes[i]=r.child),this.uncheckedNodes.pop()}},V.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},V.Index.prototype.search=function(t){return this.query(function(e){new V.QueryParser(t,e).parse()})},V.Index.prototype.query=function(e){for(var t=new V.Query(this.fields),r=Object.create(null),i=Object.create(null),n=Object.create(null),s=Object.create(null),o=Object.create(null),a=0;a<this.fields.length;a++)i[this.fields[a]]=new V.Vector;e.call(t,t);for(a=0;a<t.clauses.length;a++){var u=t.clauses[a],l=null;l=u.usePipeline?this.pipeline.runString(u.term,{fields:u.fields}):[u.term];for(var c=0;c<l.length;c++){var h=l[c];u.term=h;var d=V.TokenSet.fromClause(u),f=this.tokenSet.intersect(d).toArray();if(0===f.length&&u.presence===V.Query.presence.REQUIRED){for(var p=0;p<u.fields.length;p++){s[O=u.fields[p]]=V.Set.empty}break}for(var y=0;y<f.length;y++){var m=f[y],g=this.invertedIndex[m],x=g._index;for(p=0;p<u.fields.length;p++){var v=g[O=u.fields[p]],w=Object.keys(v),Q=m+"/"+O,k=new V.Set(w);if(u.presence==V.Query.presence.REQUIRED&&(void 0===s[O]&&(s[O]=V.Set.complete),s[O]=s[O].intersect(k)),u.presence!=V.Query.presence.PROHIBITED){if(i[O].upsert(x,1*u.boost,function(e,t){return e+t}),!n[Q]){for(var S=0;S<w.length;S++){var L,E=w[S],T=new V.FieldRef(E,O),b=v[E];void 0===(L=r[T])?r[T]=new V.MatchData(m,O,b):L.add(m,O,b)}n[Q]=!0}}else void 0===o[O]&&(o[O]=V.Set.empty),o[O]=o[O].union(k)}}}}var P=V.Set.complete,I=V.Set.empty;for(a=0;a<this.fields.length;a++){var O;s[O=this.fields[a]]&&(P=P.union(s[O])),o[O]&&(I=I.union(o[O]))}var R=Object.keys(r),F=[],N=Object.create(null);if(t.isNegated()){R=Object.keys(this.fieldVectors);for(a=0;a<R.length;a++){T=R[a];var C=V.FieldRef.fromString(T);r[T]=new V.MatchData}}for(a=0;a<R.length;a++){var _=(C=V.FieldRef.fromString(R[a])).docRef;if(P.contains(_)&&!I.contains(_)){var j,D=this.fieldVectors[C],A=i[C.fieldName].similarity(D);if(void 0!==(j=N[_]))j.score+=A,j.matchData.combine(r[C]);else{var B={ref:_,score:A,matchData:r[C]};N[_]=B,F.push(B)}}}return F.sort(function(e,t){return t.score-e.score})},V.Index.prototype.toJSON=function(){var e=Object.keys(this.invertedIndex).sort().map(function(e){return[e,this.invertedIndex[e]]},this),t=Object.keys(this.fieldVectors).map(function(e){return[e,this.fieldVectors[e].toJSON()]},this);return{version:V.version,fields:this.fields,fieldVectors:t,invertedIndex:e,pipeline:this.pipeline.toJSON()}},V.Index.load=function(e){var t={},r={},i=e.fieldVectors,n={},s=e.invertedIndex,o=new V.TokenSet.Builder,a=V.Pipeline.load(e.pipeline);e.version!=V.version&&V.utils.warn("Version mismatch when loading serialised index. Current version of lunr '"+V.version+"' does not match serialized index '"+e.version+"'");for(var u=0;u<i.length;u++){var l=(h=i[u])[0],c=h[1];r[l]=new V.Vector(c)}for(u=0;u<s.length;u++){var h,d=(h=s[u])[0],f=h[1];o.insert(d),n[d]=f}return o.finish(),t.fields=e.fields,t.fieldVectors=r,t.invertedIndex=n,t.tokenSet=o.root,t.pipeline=a,new V.Index(t)},V.Builder=function(){this._ref="id",this._fields=[],this.invertedIndex=Object.create(null),this.fieldTermFrequencies={},this.fieldLengths={},this.tokenizer=V.tokenizer,this.pipeline=new V.Pipeline,this.searchPipeline=new V.Pipeline,this.documentCount=0,this._b=.75,this._k1=1.2,this.termIndex=0,this.metadataWhitelist=[]},V.Builder.prototype.ref=function(e){this._ref=e},V.Builder.prototype.field=function(e){this._fields.push(e)},V.Builder.prototype.b=function(e){this._b=e<0?0:1<e?1:e},V.Builder.prototype.k1=function(e){this._k1=e},V.Builder.prototype.add=function(e){var t=e[this._ref];this.documentCount+=1;for(var r=0;r<this._fields.length;r++){var i=this._fields[r],n=e[i],s=this.tokenizer(n,{fields:[i]}),o=this.pipeline.run(s),a=new V.FieldRef(t,i),u=Object.create(null);this.fieldTermFrequencies[a]=u,this.fieldLengths[a]=0,this.fieldLengths[a]+=o.length;for(var l=0;l<o.length;l++){var c=o[l];if(null==u[c]&&(u[c]=0),u[c]+=1,null==this.invertedIndex[c]){var h=Object.create(null);h._index=this.termIndex,this.termIndex+=1;for(var d=0;d<this._fields.length;d++)h[this._fields[d]]=Object.create(null);this.invertedIndex[c]=h}null==this.invertedIndex[c][i][t]&&(this.invertedIndex[c][i][t]=Object.create(null));for(var f=0;f<this.metadataWhitelist.length;f++){var p=this.metadataWhitelist[f],y=c.metadata[p];null==this.invertedIndex[c][i][t][p]&&(this.invertedIndex[c][i][t][p]=[]),this.invertedIndex[c][i][t][p].push(y)}}}},V.Builder.prototype.calculateAverageFieldLengths=function(){for(var e=Object.keys(this.fieldLengths),t=e.length,r={},i={},n=0;n<t;n++){var s=V.FieldRef.fromString(e[n]);i[o=s.fieldName]||(i[o]=0),i[o]+=1,r[o]||(r[o]=0),r[o]+=this.fieldLengths[s]}for(n=0;n<this._fields.length;n++){var o;r[o=this._fields[n]]=r[o]/i[o]}this.averageFieldLength=r},V.Builder.prototype.createFieldVectors=function(){for(var e={},t=Object.keys(this.fieldTermFrequencies),r=t.length,i=Object.create(null),n=0;n<r;n++){for(var s=V.FieldRef.fromString(t[n]),o=s.fieldName,a=this.fieldLengths[s],u=new V.Vector,l=this.fieldTermFrequencies[s],c=Object.keys(l),h=c.length,d=0;d<h;d++){var f,p,y,m=c[d],g=l[m],x=this.invertedIndex[m]._index;void 0===i[m]?(f=V.idf(this.invertedIndex[m],this.documentCount),i[m]=f):f=i[m],p=f*((this._k1+1)*g)/(this._k1*(1-this._b+this._b*(a/this.averageFieldLength[o]))+g),y=Math.round(1e3*p)/1e3,u.insert(x,y)}e[s]=u}this.fieldVectors=e},V.Builder.prototype.createTokenSet=function(){this.tokenSet=V.TokenSet.fromArray(Object.keys(this.invertedIndex).sort())},V.Builder.prototype.build=function(){return this.calculateAverageFieldLengths(),this.createFieldVectors(),this.createTokenSet(),new V.Index({invertedIndex:this.invertedIndex,fieldVectors:this.fieldVectors,tokenSet:this.tokenSet,fields:this._fields,pipeline:this.searchPipeline})},V.Builder.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},V.MatchData=function(e,t,r){for(var i=Object.create(null),n=Object.keys(r||{}),s=0;s<n.length;s++){var o=n[s];i[o]=r[o].slice()}this.metadata=Object.create(null),void 0!==e&&(this.metadata[e]=Object.create(null),this.metadata[e][t]=i)},V.MatchData.prototype.combine=function(e){for(var t=Object.keys(e.metadata),r=0;r<t.length;r++){var i=t[r],n=Object.keys(e.metadata[i]);null==this.metadata[i]&&(this.metadata[i]=Object.create(null));for(var s=0;s<n.length;s++){var o=n[s],a=Object.keys(e.metadata[i][o]);null==this.metadata[i][o]&&(this.metadata[i][o]=Object.create(null));for(var u=0;u<a.length;u++){var l=a[u];null==this.metadata[i][o][l]?this.metadata[i][o][l]=e.metadata[i][o][l]:this.metadata[i][o][l]=this.metadata[i][o][l].concat(e.metadata[i][o][l])}}}},V.MatchData.prototype.add=function(e,t,r){if(!(e in this.metadata))return this.metadata[e]=Object.create(null),void(this.metadata[e][t]=r);if(t in this.metadata[e])for(var i=Object.keys(r),n=0;n<i.length;n++){var s=i[n];s in this.metadata[e][t]?this.metadata[e][t][s]=this.metadata[e][t][s].concat(r[s]):this.metadata[e][t][s]=r[s]}else this.metadata[e][t]=r},V.Query=function(e){this.clauses=[],this.allFields=e},V.Query.wildcard=new String("*"),V.Query.wildcard.NONE=0,V.Query.wildcard.LEADING=1,V.Query.wildcard.TRAILING=2,V.Query.presence={OPTIONAL:1,REQUIRED:2,PROHIBITED:3},V.Query.prototype.clause=function(e){return"fields"in e||(e.fields=this.allFields),"boost"in e||(e.boost=1),"usePipeline"in e||(e.usePipeline=!0),"wildcard"in e||(e.wildcard=V.Query.wildcard.NONE),e.wildcard&V.Query.wildcard.LEADING&&e.term.charAt(0)!=V.Query.wildcard&&(e.term="*"+e.term),e.wildcard&V.Query.wildcard.TRAILING&&e.term.slice(-1)!=V.Query.wildcard&&(e.term=e.term+"*"),"presence"in e||(e.presence=V.Query.presence.OPTIONAL),this.clauses.push(e),this},V.Query.prototype.isNegated=function(){for(var e=0;e<this.clauses.length;e++)if(this.clauses[e].presence!=V.Query.presence.PROHIBITED)return!1;return!0},V.Query.prototype.term=function(e,t){if(Array.isArray(e))return e.forEach(function(e){this.term(e,t)},this),this;var r=t||{};return r.term=e.toString(),this.clause(r),this},V.QueryParseError=function(e,t,r){this.name="QueryParseError",this.message=e,this.start=t,this.end=r},V.QueryParseError.prototype=new Error,V.QueryLexer=function(e){this.lexemes=[],this.str=e,this.length=e.length,this.pos=0,this.start=0,this.escapeCharPositions=[]},V.QueryLexer.prototype.run=function(){for(var e=V.QueryLexer.lexText;e;)e=e(this)},V.QueryLexer.prototype.sliceString=function(){for(var e=[],t=this.start,r=this.pos,i=0;i<this.escapeCharPositions.length;i++)r=this.escapeCharPositions[i],e.push(this.str.slice(t,r)),t=r+1;return e.push(this.str.slice(t,this.pos)),this.escapeCharPositions.length=0,e.join("")},V.QueryLexer.prototype.emit=function(e){this.lexemes.push({type:e,str:this.sliceString(),start:this.start,end:this.pos}),this.start=this.pos},V.QueryLexer.prototype.escapeCharacter=function(){this.escapeCharPositions.push(this.pos-1),this.pos+=1},V.QueryLexer.prototype.next=function(){if(this.pos>=this.length)return V.QueryLexer.EOS;var e=this.str.charAt(this.pos);return this.pos+=1,e},V.QueryLexer.prototype.width=function(){return this.pos-this.start},V.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},V.QueryLexer.prototype.backup=function(){this.pos-=1},V.QueryLexer.prototype.acceptDigitRun=function(){for(var e,t;47<(t=(e=this.next()).charCodeAt(0))&&t<58;);e!=V.QueryLexer.EOS&&this.backup()},V.QueryLexer.prototype.more=function(){return this.pos<this.length},V.QueryLexer.EOS="EOS",V.QueryLexer.FIELD="FIELD",V.QueryLexer.TERM="TERM",V.QueryLexer.EDIT_DISTANCE="EDIT_DISTANCE",V.QueryLexer.BOOST="BOOST",V.QueryLexer.PRESENCE="PRESENCE",V.QueryLexer.lexField=function(e){return e.backup(),e.emit(V.QueryLexer.FIELD),e.ignore(),V.QueryLexer.lexText},V.QueryLexer.lexTerm=function(e){if(1<e.width()&&(e.backup(),e.emit(V.QueryLexer.TERM)),e.ignore(),e.more())return V.QueryLexer.lexText},V.QueryLexer.lexEditDistance=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(V.QueryLexer.EDIT_DISTANCE),V.QueryLexer.lexText},V.QueryLexer.lexBoost=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(V.QueryLexer.BOOST),V.QueryLexer.lexText},V.QueryLexer.lexEOS=function(e){0<e.width()&&e.emit(V.QueryLexer.TERM)},V.QueryLexer.termSeparator=V.tokenizer.separator,V.QueryLexer.lexText=function(e){for(;;){var t=e.next();if(t==V.QueryLexer.EOS)return V.QueryLexer.lexEOS;if(92!=t.charCodeAt(0)){if(":"==t)return V.QueryLexer.lexField;if("~"==t)return e.backup(),0<e.width()&&e.emit(V.QueryLexer.TERM),V.QueryLexer.lexEditDistance;if("^"==t)return e.backup(),0<e.width()&&e.emit(V.QueryLexer.TERM),V.QueryLexer.lexBoost;if("+"==t&&1===e.width())return e.emit(V.QueryLexer.PRESENCE),V.QueryLexer.lexText;if("-"==t&&1===e.width())return e.emit(V.QueryLexer.PRESENCE),V.QueryLexer.lexText;if(t.match(V.QueryLexer.termSeparator))return V.QueryLexer.lexTerm}else e.escapeCharacter()}},V.QueryParser=function(e,t){this.lexer=new V.QueryLexer(e),this.query=t,this.currentClause={},this.lexemeIdx=0},V.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var e=V.QueryParser.parseClause;e;)e=e(this);return this.query},V.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},V.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},V.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},V.QueryParser.parseClause=function(e){var t=e.peekLexeme();if(null!=t)switch(t.type){case V.QueryLexer.PRESENCE:return V.QueryParser.parsePresence;case V.QueryLexer.FIELD:return V.QueryParser.parseField;case V.QueryLexer.TERM:return V.QueryParser.parseTerm;default:var r="expected either a field or a term, found "+t.type;throw 1<=t.str.length&&(r+=" with value '"+t.str+"'"),new V.QueryParseError(r,t.start,t.end)}},V.QueryParser.parsePresence=function(e){var t=e.consumeLexeme();if(null!=t){switch(t.str){case"-":e.currentClause.presence=V.Query.presence.PROHIBITED;break;case"+":e.currentClause.presence=V.Query.presence.REQUIRED;break;default:var r="unrecognised presence operator'"+t.str+"'";throw new V.QueryParseError(r,t.start,t.end)}var i=e.peekLexeme();if(null==i){r="expecting term or field, found nothing";throw new V.QueryParseError(r,t.start,t.end)}switch(i.type){case V.QueryLexer.FIELD:return V.QueryParser.parseField;case V.QueryLexer.TERM:return V.QueryParser.parseTerm;default:r="expecting term or field, found '"+i.type+"'";throw new V.QueryParseError(r,i.start,i.end)}}},V.QueryParser.parseField=function(e){var t=e.consumeLexeme();if(null!=t){if(-1==e.query.allFields.indexOf(t.str)){var r=e.query.allFields.map(function(e){return"'"+e+"'"}).join(", "),i="unrecognised field '"+t.str+"', possible fields: "+r;throw new V.QueryParseError(i,t.start,t.end)}e.currentClause.fields=[t.str];var n=e.peekLexeme();if(null==n){i="expecting term, found nothing";throw new V.QueryParseError(i,t.start,t.end)}switch(n.type){case V.QueryLexer.TERM:return V.QueryParser.parseTerm;default:i="expecting term, found '"+n.type+"'";throw new V.QueryParseError(i,n.start,n.end)}}},V.QueryParser.parseTerm=function(e){var t=e.consumeLexeme();if(null!=t){e.currentClause.term=t.str.toLowerCase(),-1!=t.str.indexOf("*")&&(e.currentClause.usePipeline=!1);var r=e.peekLexeme();if(null!=r)switch(r.type){case V.QueryLexer.TERM:return e.nextClause(),V.QueryParser.parseTerm;case V.QueryLexer.FIELD:return e.nextClause(),V.QueryParser.parseField;case V.QueryLexer.EDIT_DISTANCE:return V.QueryParser.parseEditDistance;case V.QueryLexer.BOOST:return V.QueryParser.parseBoost;case V.QueryLexer.PRESENCE:return e.nextClause(),V.QueryParser.parsePresence;default:var i="Unexpected lexeme type '"+r.type+"'";throw new V.QueryParseError(i,r.start,r.end)}else e.nextClause()}},V.QueryParser.parseEditDistance=function(e){var t=e.consumeLexeme();if(null!=t){var r=parseInt(t.str,10);if(isNaN(r)){var i="edit distance must be numeric";throw new V.QueryParseError(i,t.start,t.end)}e.currentClause.editDistance=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case V.QueryLexer.TERM:return e.nextClause(),V.QueryParser.parseTerm;case V.QueryLexer.FIELD:return e.nextClause(),V.QueryParser.parseField;case V.QueryLexer.EDIT_DISTANCE:return V.QueryParser.parseEditDistance;case V.QueryLexer.BOOST:return V.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new V.QueryParseError(i,n.start,n.end)}else e.nextClause()}},V.QueryParser.parseBoost=function(e){var t=e.consumeLexeme();if(null!=t){var r=parseInt(t.str,10);if(isNaN(r)){var i="boost must be numeric";throw new V.QueryParseError(i,t.start,t.end)}e.currentClause.boost=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case V.QueryLexer.TERM:return e.nextClause(),V.QueryParser.parseTerm;case V.QueryLexer.FIELD:return e.nextClause(),V.QueryParser.parseField;case V.QueryLexer.EDIT_DISTANCE:return V.QueryParser.parseEditDistance;case V.QueryLexer.BOOST:return V.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new V.QueryParseError(i,n.start,n.end)}else e.nextClause()}},n=this,s=function(){return V},"function"==typeof define&&define.amd?define(s):"object"==typeof exports?module.exports=s():n.lunr=s()}();