!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;r1&&(se&&(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:sa?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;t0)(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=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;n1?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.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.pos1&&(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()}();