You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
24 KiB

!function(){var e,t,r,i,n,s,o,a,u,l,d,h,c,f,p,y,m,g,x,v,w,k,Q,L,T,S,b,P,E=function(e){var t=new E.Builder;return t.pipeline.add(E.trimmer,E.stopWordFilter,E.stemmer),t.searchPipeline.add(E.stemmer),e.call(t,t),t.build()};E.version="2.1.2",E.utils={},E.utils.warn=(e=this,function(t){e.console&&console.warn&&console.warn(t)}),E.utils.asString=function(e){return null==e?"":e.toString()},E.FieldRef=function(e,t){this.docRef=e,this.fieldName=t,this._stringValue=t+E.FieldRef.joiner+e},E.FieldRef.joiner="/",E.FieldRef.fromString=function(e){var t=e.indexOf(E.FieldRef.joiner);if(-1===t)throw"malformed field ref string";var r=e.slice(0,t),i=e.slice(t+1);return new E.FieldRef(i,r)},E.FieldRef.prototype.toString=function(){return this._stringValue},E.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))},E.Token=function(e,t){this.str=e||"",this.metadata=t||{}},E.Token.prototype.toString=function(){return this.str},E.Token.prototype.update=function(e){return this.str=e(this.str,this.metadata),this},E.Token.prototype.clone=function(e){return e=e||function(e){return e},new E.Token(e(this.str,this.metadata),this.metadata)},E.tokenizer=function(e){if(null==e||null==e)return[];if(Array.isArray(e))return e.map(function(e){return new E.Token(E.utils.asString(e).toLowerCase())});for(var t=e.toString().trim().toLowerCase(),r=t.length,i=[],n=0,s=0;n<=r;n++){var o=n-s;(t.charAt(n).match(E.tokenizer.separator)||n==r)&&(o>0&&i.push(new E.Token(t.slice(s,n),{position:[s,o],index:i.length})),s=n+1)}return i},E.tokenizer.separator=/[\s\-]+/,E.Pipeline=function(){this._stack=[]},E.Pipeline.registeredFunctions=Object.create(null),E.Pipeline.registerFunction=function(e,t){t in this.registeredFunctions&&E.utils.warn("Overwriting existing registered function: "+t),e.label=t,E.Pipeline.registeredFunctions[e.label]=e},E.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||E.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},E.Pipeline.load=function(e){var t=new E.Pipeline;return e.forEach(function(e){var r=E.Pipeline.registeredFunctions[e];if(!r)throw new Error("Cannot load unregistered function: "+e);t.add(r)}),t},E.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){E.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},E.Pipeline.prototype.after=function(e,t){E.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)},E.Pipeline.prototype.before=function(e,t){E.Pipeline.warnIfFunctionNotRegistered(t);var r=this._stack.indexOf(e);if(-1==r)throw new Error("Cannot find existingFn");this._stack.splice(r,0,t)},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=this._stack.length,r=0;r<t;r++){var i=this._stack[r];e=e.reduce(function(t,r,n){var s=i(r,n,e);return void 0===s||""===s?t:t.concat(s)},[])}return e},E.Pipeline.prototype.runString=function(e){var t=new E.Token(e);return this.run([t]).map(function(e){return e.toString()})},E.Pipeline.prototype.reset=function(){this._stack=[]},E.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return E.Pipeline.warnIfFunctionNotRegistered(e),e.label})},E.Vector=function(e){this._magnitude=0,this.elements=e||[]},E.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];i>1&&(s<e&&(t=n),s>e&&(r=n),s!=e);)i=r-t,n=t+Math.floor(i/2),s=this.elements[2*n];return s==e?2*n:s>e?2*n:s<e?2*(n+1):void 0},E.Vector.prototype.insert=function(e,t){this.upsert(e,t,function(){throw"duplicate index"})},E.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)},E.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)},E.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:o>a?l+=2:o==a&&(t+=r[u+1]*i[l+1],u+=2,l+=2);return t},E.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},E.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},E.Vector.prototype.toJSON=function(){return this.elements},E.stemmer=(t={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"},r={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},i="[aeiouy]",n="[^aeiou][^aeiouy]*",s=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),o=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),a=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$"),u=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy]"),l=/^(.+?)(ss|i)es$/,d=/^(.+?)([^s])s$/,h=/^(.+?)eed$/,c=/^(.+?)(ed|ing)$/,f=/.$/,p=/(at|bl|iz)$/,y=new RegExp("([^aeiouylsz])\\1$"),m=new RegExp("^"+n+i+"[^aeiouwxy]$"),g=/^(.+?[^aeiou])y$/,x=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,v=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,w=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,k=/^(.+?)(s|t)(ion)$/,Q=/^(.+?)e$/,L=/ll$/,T=new RegExp("^"+n+i+"[^aeiouwxy]$"),S=function(e){var i,n,S,b,P,E,I;if(e.length<3)return e;if("y"==(S=e.substr(0,1))&&(e=S.toUpperCase()+e.substr(1)),P=d,(b=l).test(e)?e=e.replace(b,"$1$2"):P.test(e)&&(e=e.replace(P,"$1$2")),P=c,(b=h).test(e)){var F=b.exec(e);(b=s).test(F[1])&&(b=f,e=e.replace(b,""))}else if(P.test(e)){i=(F=P.exec(e))[1],(P=u).test(i)&&(E=y,I=m,(P=p).test(e=i)?e+="e":E.test(e)?(b=f,e=e.replace(b,"")):I.test(e)&&(e+="e"))}if((b=g).test(e)&&(e=(i=(F=b.exec(e))[1])+"i"),(b=x).test(e)&&(i=(F=b.exec(e))[1],n=F[2],(b=s).test(i)&&(e=i+t[n])),(b=v).test(e)&&(i=(F=b.exec(e))[1],n=F[2],(b=s).test(i)&&(e=i+r[n])),P=k,(b=w).test(e))i=(F=b.exec(e))[1],(b=o).test(i)&&(e=i);else if(P.test(e)){i=(F=P.exec(e))[1]+F[2],(P=o).test(i)&&(e=i)}return(b=Q).test(e)&&(i=(F=b.exec(e))[1],P=a,E=T,((b=o).test(i)||P.test(i)&&!E.test(i))&&(e=i)),P=o,(b=L).test(e)&&P.test(e)&&(b=f,e=e.replace(b,"")),"y"==S&&(e=S.toLowerCase()+e.substr(1)),e},function(e){return e.update(S)}),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){if(e&&t[e.toString()]!==e.toString())return e}},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){return e.update(function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")})},E.Pipeline.registerFunction(E.trimmer,"trimmer"),E.TokenSet=function(){this.final=!1,this.edges={},this.id=E.TokenSet._nextId,E.TokenSet._nextId+=1},E.TokenSet._nextId=1,E.TokenSet.fromArray=function(e){for(var t=new E.TokenSet.Builder,r=0,i=e.length;r<i;r++)t.insert(e[r]);return t.finish(),t.root},E.TokenSet.fromClause=function(e){return"editDistance"in e?E.TokenSet.fromFuzzyString(e.term,e.editDistance):E.TokenSet.fromString(e.term)},E.TokenSet.fromFuzzyString=function(e,t){for(var r=new E.TokenSet,i=[{node:r,editsRemaining:t,str:e}];i.length;){var n,s,o,a=i.pop();if(a.str.length>0)(s=a.str.charAt(0))in a.node.edges?n=a.node.edges[s]:(n=new E.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(a.editsRemaining>0&&a.str.length>1)(s=a.str.charAt(1))in a.node.edges?o=a.node.edges[s]:(o=new E.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(a.editsRemaining>0&&1==a.str.length&&(a.node.final=!0),a.editsRemaining>0&&a.str.length>=1){if("*"in a.node.edges)var u=a.node.edges["*"];else{u=new E.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(a.editsRemaining>0){if("*"in a.node.edges)var l=a.node.edges["*"];else{l=new E.TokenSet;a.node.edges["*"]=l}0==a.str.length?l.final=!0:i.push({node:l,editsRemaining:a.editsRemaining-1,str:a.str})}if(a.editsRemaining>0&&a.str.length>1){var d,h=a.str.charAt(0),c=a.str.charAt(1);c in a.node.edges?d=a.node.edges[c]:(d=new E.TokenSet,a.node.edges[c]=d),1==a.str.length?d.final=!0:i.push({node:d,editsRemaining:a.editsRemaining-1,str:h+a.str.slice(2)})}}return r},E.TokenSet.fromString=function(e){for(var t=new E.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,t.final=a;else{var u=new E.TokenSet;u.final=a,t.edges[o]=u,t=u,i&&(t.edges["*"]=r)}}return r},E.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},E.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},E.TokenSet.prototype.intersect=function(e){for(var t=new E.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],d=0;d<a;d++){var h=o[d];if(h==l||"*"==l){var c=r.node.edges[h],f=r.qNode.edges[l],p=c.final&&f.final,y=void 0;h in r.output.edges?(y=r.output.edges[h]).final=y.final||p:((y=new E.TokenSet).final=p,r.output.edges[h]=y),i.push({qNode:f,output:y,node:c})}}}return t},E.TokenSet.Builder=function(){this.previousWord="",this.root=new E.TokenSet,this.uncheckedNodes=[],this.minimizedNodes={}},E.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 E.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},E.TokenSet.Builder.prototype.finish=function(){this.minimize(0)},E.TokenSet.Builder.prototype.minimize=function(e){for(var t=this.uncheckedNodes.length-1;t>=e;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()}},E.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},E.Index.prototype.search=function(e){return this.query(function(t){new E.QueryParser(e,t).parse()})},E.Index.prototype.query=function(e){var t=new E.Query(this.fields),r=Object.create(null),i=Object.create(null);e.call(t,t);for(var n=0;n<t.clauses.length;n++){var s=t.clauses[n],o=null;o=s.usePipeline?this.pipeline.runString(s.term):[s.term];for(var a=0;a<o.length;a++){var u=o[a];s.term=u;for(var l=E.TokenSet.fromClause(s),d=this.tokenSet.intersect(l).toArray(),h=0;h<d.length;h++)for(var c=d[h],f=this.invertedIndex[c],p=f._index,y=0;y<s.fields.length;y++){var m=s.fields[y],g=f[m],x=Object.keys(g);m in i||(i[m]=new E.Vector),i[m].upsert(p,1*s.boost,function(e,t){return e+t});for(var v=0;v<x.length;v++){var w,k,Q=x[v],L=new E.FieldRef(Q,m);w=g[Q],k=new E.MatchData(c,m,w),L in r?r[L].combine(k):r[L]=k}}}}var T=Object.keys(r),S={};for(n=0;n<T.length;n++){var b=E.FieldRef.fromString(T[n]),P=b.docRef,I=this.fieldVectors[b],F=i[b.fieldName].similarity(I);P in S?(S[P].score+=F,S[P].matchData.combine(r[b])):S[P]={ref:P,score:F,matchData:r[b]}}return Object.keys(S).map(function(e){return S[e]}).sort(function(e,t){return t.score-e.score})},E.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:E.version,fields:this.fields,fieldVectors:t,invertedIndex:e,pipeline:this.pipeline.toJSON()}},E.Index.load=function(e){var t={},r={},i=e.fieldVectors,n={},s=e.invertedIndex,o=new E.TokenSet.Builder,a=E.Pipeline.load(e.pipeline);e.version!=E.version&&E.utils.warn("Version mismatch when loading serialised index. Current version of lunr '"+E.version+"' does not match serialized index '"+e.version+"'");for(var u=0;u<i.length;u++){var l=(h=i[u])[0],d=h[1];r[l]=new E.Vector(d)}for(u=0;u<s.length;u++){var h,c=(h=s[u])[0],f=h[1];o.insert(c),n[c]=f}return o.finish(),t.fields=e.fields,t.fieldVectors=r,t.invertedIndex=n,t.tokenSet=o.root,t.pipeline=a,new E.Index(t)},E.Builder=function(){this._ref="id",this._fields=[],this.invertedIndex=Object.create(null),this.fieldTermFrequencies={},this.fieldLengths={},this.tokenizer=E.tokenizer,this.pipeline=new E.Pipeline,this.searchPipeline=new E.Pipeline,this.documentCount=0,this._b=.75,this._k1=1.2,this.termIndex=0,this.metadataWhitelist=[]},E.Builder.prototype.ref=function(e){this._ref=e},E.Builder.prototype.field=function(e){this._fields.push(e)},E.Builder.prototype.b=function(e){this._b=e<0?0:e>1?1:e},E.Builder.prototype.k1=function(e){this._k1=e},E.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),o=this.pipeline.run(s),a=new E.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 d=o[l];if(null==u[d]&&(u[d]=0),u[d]+=1,null==this.invertedIndex[d]){var h=Object.create(null);h._index=this.termIndex,this.termIndex+=1;for(var c=0;c<this._fields.length;c++)h[this._fields[c]]=Object.create(null);this.invertedIndex[d]=h}null==this.invertedIndex[d][i][t]&&(this.invertedIndex[d][i][t]=Object.create(null));for(var f=0;f<this.metadataWhitelist.length;f++){var p=this.metadataWhitelist[f],y=d.metadata[p];null==this.invertedIndex[d][i][t][p]&&(this.invertedIndex[d][i][t][p]=[]),this.invertedIndex[d][i][t][p].push(y)}}}},E.Builder.prototype.calculateAverageFieldLengths=function(){for(var e=Object.keys(this.fieldLengths),t=e.length,r={},i={},n=0;n<t;n++){var s=E.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},E.Builder.prototype.createFieldVectors=function(){for(var e={},t=Object.keys(this.fieldTermFrequencies),r=t.length,i=0;i<r;i++){for(var n=E.FieldRef.fromString(t[i]),s=n.fieldName,o=this.fieldLengths[n],a=new E.Vector,u=this.fieldTermFrequencies[n],l=Object.keys(u),d=l.length,h=0;h<d;h++){var c=l[h],f=u[c],p=this.invertedIndex[c]._index,y=E.idf(this.invertedIndex[c],this.documentCount)*((this._k1+1)*f)/(this._k1*(1-this._b+this._b*(o/this.averageFieldLength[s]))+f),m=Math.round(1e3*y)/1e3;a.insert(p,m)}e[n]=a}this.fieldVectors=e},E.Builder.prototype.createTokenSet=function(){this.tokenSet=E.TokenSet.fromArray(Object.keys(this.invertedIndex).sort())},E.Builder.prototype.build=function(){return this.calculateAverageFieldLengths(),this.createFieldVectors(),this.createTokenSet(),new E.Index({invertedIndex:this.invertedIndex,fieldVectors:this.fieldVectors,tokenSet:this.tokenSet,fields:this._fields,pipeline:this.searchPipeline})},E.Builder.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},E.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),this.metadata[e]=Object.create(null),this.metadata[e][t]=i},E.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])}}}},E.Query=function(e){this.clauses=[],this.allFields=e},E.Query.wildcard=new String("*"),E.Query.wildcard.NONE=0,E.Query.wildcard.LEADING=1,E.Query.wildcard.TRAILING=2,E.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=E.Query.wildcard.NONE),e.wildcard&E.Query.wildcard.LEADING&&e.term.charAt(0)!=E.Query.wildcard&&(e.term="*"+e.term),e.wildcard&E.Query.wildcard.TRAILING&&e.term.slice(-1)!=E.Query.wildcard&&(e.term=e.term+"*"),this.clauses.push(e),this},E.Query.prototype.term=function(e,t){var r=t||{};return r.term=e,this.clause(r),this},E.QueryParseError=function(e,t,r){this.name="QueryParseError",this.message=e,this.start=t,this.end=r},E.QueryParseError.prototype=new Error,E.QueryLexer=function(e){this.lexemes=[],this.str=e,this.length=e.length,this.pos=0,this.start=0,this.escapeCharPositions=[]},E.QueryLexer.prototype.run=function(){for(var e=E.QueryLexer.lexText;e;)e=e(this)},E.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("")},E.QueryLexer.prototype.emit=function(e){this.lexemes.push({type:e,str:this.sliceString(),start:this.start,end:this.pos}),this.start=this.pos},E.QueryLexer.prototype.escapeCharacter=function(){this.escapeCharPositions.push(this.pos-1),this.pos+=1},E.QueryLexer.prototype.next=function(){if(this.pos>=this.length)return E.QueryLexer.EOS;var e=this.str.charAt(this.pos);return this.pos+=1,e},E.QueryLexer.prototype.width=function(){return this.pos-this.start},E.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},E.QueryLexer.prototype.backup=function(){this.pos-=1},E.QueryLexer.prototype.acceptDigitRun=function(){var e,t;do{t=(e=this.next()).charCodeAt(0)}while(t>47&&t<58);e!=E.QueryLexer.EOS&&this.backup()},E.QueryLexer.prototype.more=function(){return this.pos<this.length},E.QueryLexer.EOS="EOS",E.QueryLexer.FIELD="FIELD",E.QueryLexer.TERM="TERM",E.QueryLexer.EDIT_DISTANCE="EDIT_DISTANCE",E.QueryLexer.BOOST="BOOST",E.QueryLexer.lexField=function(e){return e.backup(),e.emit(E.QueryLexer.FIELD),e.ignore(),E.QueryLexer.lexText},E.QueryLexer.lexTerm=function(e){if(e.width()>1&&(e.backup(),e.emit(E.QueryLexer.TERM)),e.ignore(),e.more())return E.QueryLexer.lexText},E.QueryLexer.lexEditDistance=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(E.QueryLexer.EDIT_DISTANCE),E.QueryLexer.lexText},E.QueryLexer.lexBoost=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(E.QueryLexer.BOOST),E.QueryLexer.lexText},E.QueryLexer.lexEOS=function(e){e.width()>0&&e.emit(E.QueryLexer.TERM)},E.QueryLexer.termSeparator=E.tokenizer.separator,E.QueryLexer.lexText=function(e){for(;;){var t=e.next();if(t==E.QueryLexer.EOS)return E.QueryLexer.lexEOS;if(92!=t.charCodeAt(0)){if(":"==t)return E.QueryLexer.lexField;if("~"==t)return e.backup(),e.width()>0&&e.emit(E.QueryLexer.TERM),E.QueryLexer.lexEditDistance;if("^"==t)return e.backup(),e.width()>0&&e.emit(E.QueryLexer.TERM),E.QueryLexer.lexBoost;if(t.match(E.QueryLexer.termSeparator))return E.QueryLexer.lexTerm}else e.escapeCharacter()}},E.QueryParser=function(e,t){this.lexer=new E.QueryLexer(e),this.query=t,this.currentClause={},this.lexemeIdx=0},E.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var e=E.QueryParser.parseFieldOrTerm;e;)e=e(this);return this.query},E.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},E.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},E.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},E.QueryParser.parseFieldOrTerm=function(e){var t=e.peekLexeme();if(null!=t)switch(t.type){case E.QueryLexer.FIELD:return E.QueryParser.parseField;case E.QueryLexer.TERM:return E.QueryParser.parseTerm;default:var r="expected either a field or a term, found "+t.type;throw t.str.length>=1&&(r+=" with value '"+t.str+"'"),new E.QueryParseError(r,t.start,t.end)}},E.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 E.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 E.QueryParseError(i,t.start,t.end)}switch(n.type){case E.QueryLexer.TERM:return E.QueryParser.parseTerm;default:i="expecting term, found '"+n.type+"'";throw new E.QueryParseError(i,n.start,n.end)}}},E.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 E.QueryLexer.TERM:return e.nextClause(),E.QueryParser.parseTerm;case E.QueryLexer.FIELD:return e.nextClause(),E.QueryParser.parseField;case E.QueryLexer.EDIT_DISTANCE:return E.QueryParser.parseEditDistance;case E.QueryLexer.BOOST:return E.QueryParser.parseBoost;default:var i="Unexpected lexeme type '"+r.type+"'";throw new E.QueryParseError(i,r.start,r.end)}else e.nextClause()}},E.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 E.QueryParseError(i,t.start,t.end)}e.currentClause.editDistance=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case E.QueryLexer.TERM:return e.nextClause(),E.QueryParser.parseTerm;case E.QueryLexer.FIELD:return e.nextClause(),E.QueryParser.parseField;case E.QueryLexer.EDIT_DISTANCE:return E.QueryParser.parseEditDistance;case E.QueryLexer.BOOST:return E.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new E.QueryParseError(i,n.start,n.end)}else e.nextClause()}},E.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 E.QueryParseError(i,t.start,t.end)}e.currentClause.boost=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case E.QueryLexer.TERM:return e.nextClause(),E.QueryParser.parseTerm;case E.QueryLexer.FIELD:return e.nextClause(),E.QueryParser.parseField;case E.QueryLexer.EDIT_DISTANCE:return E.QueryParser.parseEditDistance;case E.QueryLexer.BOOST:return E.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new E.QueryParseError(i,n.start,n.end)}else e.nextClause()}},b=this,P=function(){return E},"function"==typeof define&&define.amd?define(P):"object"==typeof exports?module.exports=P():b.lunr=P()}();