elasticlunr
Version:
Lightweight full-text search engine in Javascript for browser search and offline search.
391 lines (371 loc) • 32.3 kB
HTML
<html>
<head>
<meta name="viewport" content="width=device-width" charset="utf-8">
<title>elasticlunr</title>
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css">
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css">
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/docs.css">
<style>
body > .navbar .brand {
float:left;
text-shadow: rgba(255, 255, 255, 0.0980392) 0px 1px 0px, rgba(255, 255, 255, 0.4) 0px 0px 30px;
color: white;
margin-left:0px;
font-weight:normal;
}
.bs-docs-sidenav.affix {
box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.5);
z-index: 10;
}
.bs-docs-sidenav i{
width: 8px;
height: 8px;
padding: 0px;
margin: 0px;
display: inline-block;
margin-right:0.5em;
}
.bs-docs-sidenav > li > a {
word-wrap: break-word;
}
.bs-docs-sidenav > li:first-child > a {
border-top-right-radius: 6px;
border-top-left-radius: 6px;
}
code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,'Andale Mono',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*="language-"],pre[class*="language-"]{background:#f5f2f0}:not(pre)>code[class*="language-"]{padding:.1em;border-radius:.3em}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray}.token.punctuation{color:#999}.namespace{opacity:.7}.token.property,.token.tag,.token.boolean,.token.number{color:#905}.token.selector,.token.attr-name,.token.string{color:#690}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.regex,.token.important{color:#e90}.token.important{font-weight:bold}.token.entity{cursor:help}
div.description {margin: 14px 0; padding-top: 14px; border-bottom:1px solid #eee; }
.tags {}
.ctx-type {
display:inline-block;
margin-right:0.5em;
//- float:right; margin-top:8px
}
footer iframe{vertical-align:middle;}
</style>
</head>
<body data-spy="scroll" data-target=".scrollspy">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container"><a class="brand">Doxx</a>
<div class="nav-collapse collapse">
<ul class="nav pull-right sponsored"></ul>
</div>
</div>
</div>
</div>
<header id="overview" class="jumbotron subhead">
<div class="container">
<h1>elasticlunr</h1>
<p class="lead"></p>
</div>
</header>
<div class="container">
<div class="row">
<div class="span3 bs-docs-sidebar">
<ul class="nav nav-list bs-docs-sidenav affix-top">
<li class="active"><a href="index.html">Main</a></li>
<li><a href="configuration.js.html">configuration.js</a></li>
<li><a href="document_store.js.html">document_store.js</a></li>
<li><a href="elasticlunr.js.html">elasticlunr.js</a></li>
<li><a href="event_emitter.js.html">event_emitter.js</a></li>
<li><a href="index.js.html">index.js</a></li>
<li><a href="inverted_index.js.html">inverted_index.js</a></li>
<li><a href="pipeline.js.html">pipeline.js</a></li>
<li><a href="sorted_set.js.html">sorted_set.js</a></li>
<li><a href="stemmer.js.html">stemmer.js</a></li>
<li><a href="stop_word_filter.js.html">stop_word_filter.js</a></li>
<li><a href="tokenizer.js.html">tokenizer.js</a></li>
<li><a href="trimmer.js.html">trimmer.js</a></li>
<li><a href="utils.js.html">utils.js</a></li>
</ul>
<div class="scrollspy">
<ul class="nav nav-list bs-docs-sidenav affix-top">
</ul>
</div>
</div>
<div class="span9">
<section id="Main"><h1>Elasticlunr.js</h1>
<p><a href="https://travis-ci.org/weixsong/elasticlunr.js"><img src="https://travis-ci.org/weixsong/elasticlunr.js.svg?branch=master" alt="Build Status"></a><br /><a href="https://badge.fury.io/js/elasticlunr"><img src="https://badge.fury.io/js/elasticlunr.svg" alt="npm version"></a><br /><a href="https://raw.githubusercontent.com/weixsong/elasticlunr.js/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="GitHub license"></a></p><p>Elasticlunr.js is a lightweight full-text search engine developed in JavaScript for browser search and offline search.<br />Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting, field search, more rational scoring/ranking methodology, fast computation speed and so on.<br />Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search and other features.</p><h1>Why You Need Lightweight Offline Search?</h1>
<ol>
<li>In some system, you don't want to deploy any <strong>complex full-text search engine</strong>(such as Lucence, Elasticsearch, Sphinx, etc.), you only want to provide some static web pages and provide search functionality , then you could build index in previous and load index in client side(such as Browser).</li>
<li>Provide offline search functionality. For some documents, user usually download these documents, you could build index and put index in the documents package, then provide offline search functionality.</li>
<li>For some limited or restricted network, such WAN or LAN, offline search is a better choice.</li>
<li>For mobile device, Iphone or Android phone, network traffic maybe very expensive, then provide offline search is a good choice.</li>
<li>If you want to provide search functionality in your Node.js system, and you don't want to use a complex system, or you only need to support thousands of documents, then Elasticlunr.js is what you want to use.</li>
</ol>
<h1>Key Features Comparing with Lunr.js</h1>
<ol>
<li><strong>Query-Time Boosting</strong>, you don't need to setup boosting weight in index building procedure, Query-Time Boosting make it more flexible that you could try different boosting scheme.</li>
<li><strong>More Rational Scoring Mechanism</strong>, Elasticlunr.js use quite the same scoring mechanism as Elasticsearch, and also this scoring mechanism is used by lucene. </li>
<li><strong>Field-Search</strong>, you could choose which field to index and which field to search.</li>
<li><strong>Boolean Model</strong>, you could set which field to search and the boolean model for each query token, such as "OR", "AND".</li>
<li><strong>Combined Boolean Model, TF/IDF Model and the Vector Space Model</strong>, make the results ranking more reliable.</li>
<li><strong>Fast</strong>, Elasticlunr.js removed TokenCorpus and Vector from lunr.js, by using combined model there is <strong>no</strong> need to compute the vector of a document and query string to compute similarity of query and matched document, this improve the search speed significantly.</li>
<li><strong>Small Index Size</strong>, Elasticlunr.js did not store TokenCorpus because there is no need to compute query vector and document vector, then the index file is small, and also user could choose if they need to store the origianl JSON doc, if user care more about the index size, they could choose not store the original JSON doc, this could reduce the index size significantly. This is especially helpful when elasticlunr.js is used as offline search. The index size is about half size of lunr.js index file.</li>
</ol>
<h2>Example</h2>
<p>A very simple search index can be created using the following scripts:</p><pre><code class="lang-javascript">var index = elasticlunr(function () {
this.addField('title');
this.addField('body');
this.setRef('id');
});
</code></pre>
<p>Adding documents to the index is as simple as:</p><pre><code class="lang-javascript">var doc1 = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}
var doc2 = {
"id": 2,
"title": "Oracle released its profit report of 2015",
"body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}
index.addDoc(doc1);
index.addDoc(doc2);
</code></pre>
<p>Then searching is as simple:</p><pre><code class="lang-javascript">index.search("Oracle database profit");
</code></pre>
<p>Also, you could do query-time boosting by passing in a configuration.</p><pre><code class="lang-javascript">index.search("Oracle database profit", {
fields: {
title: {boost: 2},
body: {boost: 1}
}
});
</code></pre>
<p>This returns a list of matching documents with a score of how closely they match the search query:</p><pre><code class="lang-javascript">[{
"ref": 1,
"score": 0.5376053707962494
},
{
"ref": 2,
"score": 0.5237481076838757
}]
</code></pre>
<p>If user do not want to store the original JSON documents, they could use the following setting:</p><pre><code class="lang-javascript">var index = elasticlunr(function () {
this.addField('title');
this.addField('body');
this.setRef('id');
this.saveDocument(false);
});
</code></pre>
<p>Then elasticlunr.js will not store the JSON documents, this will reduce the index size, but also bring some inconvenience such as update a document or delete a document by document id or reference. Actually most of the time user will not udpate or delete a document from index. </p><p><a href="http://elasticlunr.com/docs/index.html">API documentation</a> is available, as well as a <a href="http://elasticlunr.com/example/index.html">full working example</a>.</p><h2>Description</h2>
<p>Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time Boosting, Field Search, more rational scoring/ranking methodology, flexible configuration and so on.<br />A bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search, etc.</p><h2>Installation</h2>
<p>Simply include the elasticlunr.js source file in the page that you want to use it. Elasticlunr.js is supported in all modern browsers.</p><p>Browsers that do not support ES5 will require a JavaScript shim for Elasticlunr.js to work. You can either use <a href="https://github.com/olivernn/augment.js">Augment.js</a>, <a href="https://github.com/kriskowal/es5-shim">ES5-Shim</a> or any library that patches old browsers to provide an ES5 compatible JavaScript environment.</p><h1>Documentation</h1>
<p>This part only contain important apects of elasticlunr.js, for the whole documentation, please go to <a href="http://elasticlunr.com/docs/index.html">API documentation</a>.</p><h2>1. Build Index</h2>
<p>When you first create a index instance, you need to specify which field you want to index. If you did not specify which field to index, then no field will be searchable for your documents.<br />You could specify fields by:</p><pre><code class="lang-javascript">var index = elasticlunr(function () {
this.addField('title');
this.addField('body');
this.setRef('id');
});
</code></pre>
<p>You could also set the document reference by <code>this.setRef('id')</code>, if you did not set document ref, elasticlunr.js will use <strong>'id'</strong> as default.</p><p>You could do the above index setup as followings:</p><pre><code class="lang-javascript">var index = elasticlunr();
index.addField('title');
index.addField('body');
index.setRef('id');
</code></pre>
<p>Also you could choose not store the original JSON document to reduce the index size by:</p><pre><code class="lang-javascript">var index = elasticlunr();
index.addField('title');
index.addField('body');
index.setRef('id');
index.saveDocument(false);
</code></pre>
<h2>2. Add document to index</h2>
<p>Add document to index is very simple, just prepare you document in JSON format, then add it to index.</p><pre><code class="lang-javascript">var doc1 = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}
var doc2 = {
"id": 2,
"title": "Oracle released its profit report of 2015",
"body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}
index.addDoc(doc1);
index.addDoc(doc2);
</code></pre>
<p>If your JSON document contains field that not configured in index, then that field will not be indexed, which means that field is not searchable.</p><h2>3. Remove document from index</h2>
<p>Elasticlunr.js support remove a document from index, just provide JSON document to <code>elasticlunr.Index.prototype.removeDoc()</code> function.</p><p>For example:</p><pre><code class="lang-javascript">var doc = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}
index.removeDoc(doc);
</code></pre>
<p>Remove a document will remove each token of that document's each field from field-specified inverted index.</p><h2>4. Update a document in index</h2>
<p>Elasticlunr.js support update a document in index, just provide JSON document to <code>elasticlunr.Index.prototype.update()</code> function.</p><p>For example:</p><pre><code class="lang-javascript">var doc = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}
index.update(doc);
</code></pre>
<h2>5. Query from Index</h2>
<p>Elasticlunr.js provides flexible query configuration, supports query-time boosting and Boolean logic setting.<br />You could setup a configuration tell elasticlunr.js how to do query-time boosting, which field to search in, how to do the boolean logic.<br />Or you could just use it by simply provide a query string, this will aslo works perfectly because the scoring mechanism is very efficient.</p><h3>5.1 Simple Query</h3>
<p><strong>Because elasticlunr.js has a very perfect scoring mechanism, so for most of your requirement, simple search would be easy to meet your requirement.</strong></p><pre><code class="lang-javascript">index.search("Oracle database profit");
</code></pre>
<p>Output is a results array, each element of results array is an Object contain a <code>ref</code> field and a <code>score</code> field.<br /><code>ref</code> is the document reference.<br /><code>score</code> is the similarity measurement.</p><p>Results array is sorted descent by <code>score</code>.</p><h3>5.2 Configuration Query</h3>
<h4>5.2.1 <strong>Query-Time Boosting</strong></h4>
<p>Setup which fields to search in by passing in a JSON configuration, and setup boosting for each search field.<br />If you setup this configuration, then elasticlunr.js will only search the query string in the specified fields with boosting weight.</p><p><strong>The scoring mechanism used in elasticlunr.js is very complex</strong>, please goto <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/practical-scoring-function.html">details</a> for more information.</p><pre><code class="lang-javascript">index.search("Oracle database profit", {
fields: {
title: {boost: 2},
body: {boost: 1}
}
});
</code></pre>
<h4>5.2.2 <strong>Boolean Model</strong></h4>
<p>Elasticlunr.js also support boolean logic setting, if no boolean logic is setted, elasticlunr.js use "OR" logic defaulty. By "OR" default logic, elasticlunr.js could reach a high <strong>Recall</strong>.</p><pre><code class="lang-javascript">index.search("Oracle database profit", {
fields: {
title: {boost: 2},
body: {boost: 1}
},
bool: "OR"
});
</code></pre>
<p>Boolean model could be setted by global level such as the above setting or it could be setted by field level, if both global and field level contains a "bool" setting, field level setting will overwrite the global setting.</p><pre><code class="lang-javascript">index.search("Oracle database profit", {
fields: {
title: {boost: 2, bool: "AND"},
body: {boost: 1}
},
bool: "OR"
});
</code></pre>
<p>The above setting will search <code>title</code> field by <strong>AND</strong> model and other fields by "OR" model.<br />Currently if you search in multiply fields, resutls from each field will be merged together to give the query results. In the future elasticlunr will support configuration that user could set how to combine the results from each field, such as "most_field" or "top_field".</p><h4>5.2.3 <strong>Token Expandation</strong></h4>
<p>Sometimes user want to expand a query token to increase <strong>RECALL</strong>, then user could set expand model to <strong>true</strong> by configuration, default is <strong>false</strong>.<br />For example, user query token is "micro", and assume "microwave" and "microscope" are in the index, then is user choose expand the query token "micro" to increase <strong>RECALL</strong>, both "microwave" and "microscope" will be returned and search in the index.<br />The query results from expanded tokens are penalized because they are not exactly the same as the query token.</p><pre><code class="lang-javascript">index.search("micro", {
fields: {
title: {boost: 2, bool: "AND"},
body: {boost: 1}
},
bool: "OR",
expand: true
});
</code></pre>
<p>Field level expand configuration will overwrite global expand configuration.</p><pre><code class="lang-javascript">index.search("micro", {
fields: {
title: {
boost: 2,
bool: "AND",
expand: false
},
body: {boost: 1}
},
bool: "OR",
expand: true
});
</code></pre>
<h2>6. Add customized stop words</h2>
<p>Elasticlunr.js contains some default stop words of English, such as:</p><ul>
<li>a</li>
<li>about</li>
<li>an</li>
<li>all</li>
<li>also</li>
<li>and</li>
<li>any</li>
<li>but</li>
<li>the</li>
<li>...</li>
</ul>
<p>Defaultly elasticlunr.js contains <strong>120</strong> stop words, user could decide not use these default stop words or add customized stop words.</p><h3>6.1 Remove default stop words</h3>
<p>You could remove default stop words simply as:</p><pre><code class="lang-javascript">elasticlunr.clearStopWords();
</code></pre>
<h3>6.2 Add customized stop words</h3>
<p>User could add a list of customized stop words.</p><pre><code class="lang-javascript">var customized_stop_words = ['an', 'hello', 'xyzabc'];
elasticlunr.addStopWords(customized_stop_words);
</code></pre>
<h2>7. Use elasticlunr in Node.js</h2>
<p>Elasticlunr support Node.js, you could use elastilunr in node.js as a node-module.</p><p>Install elasticlunr by:</p><pre><code class="lang-javascript">npm install elasticlunr
</code></pre>
<p>then in your node.js project or in node.js console:</p><pre><code class="lang-javascript">var elasticlunr = require('elasticlunr');
var index = elasticlunr(function () {
this.addField('title')
this.addField('body')
});
var doc1 = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}
var doc2 = {
"id": 2,
"title": "Oracle released its profit report of 2015",
"body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}
index.addDoc(doc1);
index.addDoc(doc2);
index.search("Oracle database profit");
</code></pre>
<h1>Other Languages</h1>
<p>Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>.</p><h2>Other languages example in Browser</h2>
<p>Suppose you are using <strong>elasticlunr.js</strong> in browser for other languages, you could download the corresponding language support from <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>, then include the scripts as:</p><pre><code class="lang-html"><script src="lunr.stemmer.support.js"></script>
<script src="lunr.de.js"></script>
</code></pre>
<p>then, you could use elasticlunr.js as normal:</p><pre><code class="lang-javascript">var index = elasticlunr(function () {
// use the language (de)
this.use(elasticlunr.de);
// then, the normal elasticlunr index initialization
this.addField('title')
this.addField('body')
});
</code></pre>
<p>Pay attention to the special code:</p><pre><code class="lang-javascript"> this.use(elasticlunr.de);
</code></pre>
<p>If you are using other language, such as <strong>es</strong>(Spanish), download the corresponding <code>lunr.es.js</code> file and <code>lunr.stemmer.support.js</code>, and change the above line to:</p><pre><code class="lang-javascript"> this.use(elasticlunr.es);
</code></pre>
<h2>Other languages example in Node.js</h2>
<p>Suppose you are using <strong>elasticlunr.js</strong> in <strong>Node.js</strong> for other languages, you could download the corresponding language support from <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>, put the files <code>lunr.es.js</code> file and <code>lunr.stemmer.support.js</code> in your project, then in your <strong>Node.js</strong> module, use <strong>elasticlunr.js</strong> as:</p><pre><code class="lang-javascript">var elasticlunr = require('elasticlunr');
require('./lunr.stemmer.support.js')(elasticlunr);
require('./lunr.de.js')(elasticlunr);
var index = elasticlunr(function () {
// use the language (de)
this.use(elasticlunr.de);
// then, the normal elasticlunr index initialization
this.addField('title')
this.addField('body')
});
</code></pre>
<p>For more details, please go to <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>.</p><h1>Contributing</h1>
<p>See the <a href="CONTRIBUTING.mdown"><code>CONTRIBUTING.mdown</code> file</a>.</p></section>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p>Documentation generated with <a href="https://github.com/FGRibreau/doxx">Doxx </a> created by <a href="https://twitter.com/FGRibreau" data-show-count="false" class="twitter-follow-button">Francois-Guillaume Ribreau </a></p>
<p>Doxx is sponsored by <a href="http://bringr.net/?btt" title="Outil d'analyse des réseaux sociaux" class="bringr">Bringr </a> and <a href="https://redsmin.com/?btt" title="Full Redis GUI" class="redsmin">Redsmin</a></p>
<p>Theme borrowed from Twitter Bootstrap</p>
</div>
</footer>
<script src="http://platform.twitter.com/widgets.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="http://leaverou.github.com/prefixfree/prefixfree.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-transition.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-scrollspy.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-collapse.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-affix.js"></script>
<script>
/**
* Prism: Lightweight, robust, elegant syntax highlighting
* MIT license http://www.opensource.org/licenses/mit-license.php/
* @author Lea Verou http://lea.verou.me
*/(function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\u00a0/g," ");var l={element:r,language:o,grammar:u,code:f};t.hooks.run("before-highlight",l);if(i&&self.Worker){var c=new Worker(t.filename);c.onmessage=function(e){l.highlightedCode=n.stringify(JSON.parse(e.data));l.element.innerHTML=l.highlightedCode;s&&s.call(l.element);t.hooks.run("after-highlight",l)};c.postMessage(JSON.stringify({language:l.language,code:l.code}))}else{l.highlightedCode=t.highlight(l.code,l.grammar);l.element.innerHTML=l.highlightedCode;s&&s.call(r);t.hooks.run("after-highlight",l)}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,i=[e],s=n.rest;if(s){for(var o in s)n[o]=s[o];delete n.rest}e:for(var o in n){if(!n.hasOwnProperty(o)||!n[o])continue;var u=n[o],a=u.inside,f=!!u.lookbehind||0;u=u.pattern||u;for(var l=0;l<i.length;l++){var c=i[l];if(i.length>e.length)break e;if(c instanceof r)continue;u.lastIndex=0;var h=u.exec(c);if(h){f&&(f=h[1].length);var p=h.index-1+f,h=h[0].slice(f),d=h.length,v=p+d,m=c.slice(0,p+1),g=c.slice(v+1),y=[l,1];m&&y.push(m);var b=new r(o,a?t.tokenize(h,a):h);y.push(b);g&&y.push(g);Array.prototype.splice.apply(i,y)}}}return i},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]"){for(var r=0;r<e.length;r++)e[r]=n.stringify(e[r]);return e.join("")}var i={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};i.type=="comment"&&(i.attributes.spellcheck="true");t.hooks.run("wrap",i);var s="";for(var o in i.attributes)s+=o+'="'+(i.attributes[o]||"")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'" '+s+">"+i.content+"</"+i.tag+">"};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();;
Prism.languages.markup={comment:/<!--[\w\W]*?--(>|>)/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]+?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(e){e.type==="entity"&&(e.attributes.title=e.content.replace(/&/,"&"))});;
Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});;
Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?[\da-f]+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};;
Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,number:/\b(-?(0x)?\d*\.?[\da-f]+|NaN|-?Infinity)\b/g});Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:!0}});Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/(<|<)script[\w\W]*?(>|>)[\w\W]*?(<|<)\/script(>|>)/ig,inside:{tag:{pattern:/(<|<)script[\w\W]*?(>|>)|(<|<)\/script(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}});;
</script>
<!-- App js-->
<script>
$(function(){
var $window = $(window);
$('.scrollspy .nav').affix({
offset: {
top: function () { return $window.width() <= 980 ? 480 : 400 }
, bottom: 50
}
});
})
</script>
</body>
</html>