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.
3384 lines
214 KiB
3384 lines
214 KiB
6 years ago
|
<head>
|
||
|
<script>
|
||
|
var raw = [{"id":"1-1439115310824","name":"lunr","signiture":"lunr()","type":"function","ctx":{"type":"function","name":"lunr","string":"lunr()"},"description":{"full":"<p>Convenience function for instantiating a new lunr index and configuring it<br />with the default pipeline functions and the passed config function.</p>\n\n<p>When using this convenience function a new index will be created with the<br />following functions already in the pipeline:</p>\n\n<p>lunr.StopWordFilter - filters out any stop words before they enter the<br />index</p>\n\n<p>lunr.stemmer - stems the tokens before entering the index.</p>\n\n<p>Example:</p>\n\n<pre><code>var idx = lunr(function () {\n this.field('title', 10)\n this.field('tags', 100)\n this.field('body')\n\n this.ref('cid')\n\n this.pipeline.add(function () {\n // some custom pipeline function\n })\n\n})\n</code></pre>","summary":"<p>Convenience function for instantiating a new lunr index and configuring it<br />with the default pipeline functions and the passed config function.</p>","body":"<p>When using this convenience function a new index will be created with the<br />following functions already in the pipeline:</p>\n\n<p>lunr.StopWordFilter - filters out any stop words before they enter the<br />index</p>\n\n<p>lunr.stemmer - stems the tokens before entering the index.</p>\n\n<p>Example:</p>\n\n<pre><code>var idx = lunr(function () {\n this.field('title', 10)\n this.field('tags', 100)\n this.field('body')\n\n this.ref('cid')\n\n this.pipeline.add(function () {\n // some custom pipeline function\n })\n\n})\n</code></pre>"},"full_description":"<p>Convenience function for instantiating a new lunr index and configuring it with the default pipeline functions and the passed config function.</p>\n\n<p>When using this convenience function a new index will be created with the following functions already in the pipeline:</p>\n\n<p>lunr.StopWordFilter - filters out any stop words before they enter the index</p>\n\n<p>lunr.stemmer - stems the tokens before entering the index.</p>\n\n<p>Example:</p>\n\n<pre><code>var idx = lunr(function () {\n this.field('title', 10)\n this.field('tags', 100)\n this.field('body')\n\n this.ref('cid')\n\n this.pipeline.add(function () {\n // some custom pipeline function\n })\n\n})\n</code></pre>","code":"var lunr = function (config) {\n var idx = new lunr.Index\n\n idx.pipeline.add(\n lunr.trimmer,\n lunr.stopWordFilter,\n lunr.stemmer\n )\n\n if (config) config.call(idx, idx)\n\n return idx\n}\n\nlunr.version = \"0.5.12\"","params":[{"type":"param","types":["Function"],"name":"config","description":"A function that will be called with the new instance"}],"has_params":true,"tags":[{"type":"param","types":["Function"],"name":"config","description":"A function that will be called with the new instance"},{"type":"of","string":"the lunr.Index as both its context and first parameter. It can be used to"},{"type":"customize","string":"the instance of new lunr.Index."},{"type":"namespace","string":""},{"type":"module","string":""},{"type":"returns","string":"{lunr.Index}"}],"module":true,"related":{"href":""},"has_related":true,"methods":[]},{"id":"4-1439115310824","name":"EventEmitter","signiture":"lunr.EventEmitter()","type":"method","ctx":{"type":"method","receiver":"lunr","name":"EventEmitter","string":"lunr.EventEmitter()"},"description":{"full":"<p>lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers and triggering events and their handlers.</p>","summary":"<p>lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers and triggering events and their handlers.</p>","body":""},"full_description":"<p>lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers and triggering events and their handlers.</p>","code":"lunr.EventEmitter = function () {\n this.events = {}\n}","params":[],"has_params":false,"tags":[{"type":"constructor","string":""}],"module":true,"related":{"href":""},"has_related":true,"methods":[
|
||
|
</script>
|
||
|
|
||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
|
||
|
|
||
|
<script type="text/javascript" charset="utf-8">
|
||
|
// lunr.js version: 0.0.4
|
||
|
// (c) 2011 Oliver Nightingale
|
||
|
//
|
||
|
// Released under MIT license.
|
||
|
//
|
||
|
var Lunr=function(c,f){var b=new Lunr.Index(c);f.call(b,b);return b};
|
||
|
Lunr.utils={uniq:function(c){if(!c)return[];return c.reduce(function(c,b){c.indexOf(b)===-1&&c.push(b);return c},[])},intersect:function(c){var f=[].slice.call(arguments,1);return this.uniq(c).filter(function(b){return f.every(function(a){return a.indexOf(b)>=0})})},detect:function(c,f,b){for(var a=c.length,g=null,d=0;d<a;d++)if(f.call(b,c[d],d,c)){g=c[d];break}return g},copy:function(c){return Object.keys(c).reduce(function(f,b){f[b]=c[b];return f},{})}};
|
||
|
Lunr.Trie=function(){var c=function(){this.children={};this.values=[]};c.prototype={childForKey:function(b){var a=this.children[b];a||(a=new c,this.children[b]=a);return a}};var f=function(){this.root=new c};f.prototype={get:function(b){var a=this;return this.keys(b).reduce(function(c,d){a.getNode(d).values.forEach(function(a){a=Lunr.utils.copy(a);if(b===d)a.exact=!0;c.push(a)});return c},[])},getNode:function(b){var a=function(b,d){if(!d.length)return b;return a(b.childForKey(d.charAt(0)),d.slice(1))};
|
||
|
return a(this.root,b)},keys:function(b){var a=[];b=b||"";var c=function(b,e){b.values.length&&a.push(e);Object.keys(b.children).forEach(function(a){c(b.children[a],e+a)})};c(this.getNode(b),b);return a},set:function(b,a){var c=function(b,e){if(!e.length)return b.values.push(a);c(b.childForKey(e.charAt(0)),e.slice(1))};return c(this.root,b)}};return f}();Lunr.Index=function(c){this.name=c;this.refName="id";this.fields={};this.trie=new Lunr.Trie};
|
||
|
Lunr.Index.prototype={add:function(c){(new Lunr.Document(c,this.refName,this.fields)).words().forEach(function(c){this.trie.set(c.id,c.docs[0])},this)},field:function(c,f){this.fields[c]=f||{multiplier:1}},ref:function(c){this.refName=c},search:function(c){if(!c)return[];c=c.split(" ").map(function(c){c=new Lunr.Word(c);if(!c.isStopWord())return c.toString()}).filter(function(c){return c}).map(function(c){return this.trie.get(c).sort(function(b,a){if(b.exact&&a.exact===void 0)return-1;if(a.exact&&
|
||
|
b.exact===void 0)return 1;if(b.score<a.score)return 1;if(b.score>a.score)return-1;return 0}).map(function(b){return b.documentId})},this);return Lunr.utils.intersect.apply(Lunr.utils,c)}};Lunr.Document=function(c,f,b){this.original=c;this.fields=b;this.ref=c[f]};
|
||
|
Lunr.Document.prototype={asJSON:function(){return{id:this.ref,words:this.words().map(function(c){return c.id}),original:this.original}},words:function(){var c=this,f={};Object.keys(this.fields).forEach(function(b){c.original[b].split(/\b/g).filter(function(a){return!!a.match(/\w/)}).map(function(a){a=new Lunr.Word(a);if(!a.isStopWord())return a.toString()}).filter(function(a){return a}).forEach(function(a){f[a]||(f[a]={score:0,ref:c.ref});f[a].score+=c.fields[b].multiplier})});return Object.keys(f).map(function(b){return{id:b,
|
||
|
docs:[{score:f[b].score,documentId:c.ref}]}})}};Lunr.Word=function(c){this.raw=c;this.out=this.raw.replace(/^\W+/,"").replace(/\W+$/,"").toLowerCase()};Lunr.Word.stopWords=["the","of","to","and","a","in","is","it","you","that","this"];
|
||
|
Lunr.Word.prototype={isStopWord:function(){return Lunr.Word.stopWords.indexOf(this.raw.toLowerCase())!==-1},toString:function(){if(!this.isStopWord())return this.stem(),this.out},stem:function(){var c={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"},f={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",
|
||
|
ful:"",ness:""};return function(){var b,a,g,d=g=this.out;if(g.length<3)return g;var e,h;g=g.substr(0,1);g=="y"&&(d=g.toUpperCase()+d.substr(1));e=/^(.+?)(ss|i)es$/;a=/^(.+?)([^s])s$/;e.test(d)?d=d.replace(e,"$1$2"):a.test(d)&&(d=d.replace(a,"$1$2"));e=/^(.+?)eed$/;a=/^(.+?)(ed|ing)$/;e.test(d)?(a=e.exec(d),e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,e.test(a[1])&&(e=/.$/,d=d.replace(e,""))):a.test(d)&&(a=a.exec(d),b=a[1],a=/^([^aeiou][^aeiouy]*)?[aeiouy]/,a.test(b)&&(d=b,a=/(at|bl|iz)$/,
|
||
|
h=/([^aeiouylsz])\1$/,b=/^[^aeiou][^aeiouy]*[aeiouy][^aeiouwxy]$/,a.test(d)?d+="e":h.test(d)?(e=/.$/,d=d.replace(e,"")):b.test(d)&&(d+="e")));e=/^(.+?)y$/;e.test(d)&&(a=e.exec(d),b=a[1],e=/^([^aeiou][^aeiouy]*)?[aeiouy]/,e.test(b)&&(d=b+"i"));e=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;e.test(d)&&(a=e.exec(d),b=a[1],a=a[2],e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,e.test(b)&&(d=b+c[a]));
|
||
|
e=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;e.test(d)&&(a=e.exec(d),b=a[1],a=a[2],e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,e.test(b)&&(d=b+f[a]));e=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;a=/^(.+?)(s|t)(ion)$/;e.test(d)?(a=e.exec(d),b=a[1],e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,e.test(b)&&(d=b)):a.test(d)&&(a=a.exec(d),b=a[1]+a[2],a=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,
|
||
|
a.test(b)&&(d=b));e=/^(.+?)e$/;if(e.test(d)&&(a=e.exec(d),b=a[1],e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,a=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$/,h=/^[^aeiou][^aeiouy]*[aeiouy][^aeiouwxy]$/,e.test(b)||a.test(b)&&!h.test(b)))d=b;e=/ll$/;a=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/;e.test(d)&&a.test(d)&&(e=/.$/,d=d.replace(e,""));g=="y"&&(d=g.toLowerCase()+
|
||
|
d.substr(1));this.out=d}}()};
|
||
|
</script>
|
||
|
|
||
|
<script type="text/javascript" charset="utf-8">
|
||
|
var idx = Lunr('methods', function () {
|
||
|
this.ref('id')
|
||
|
this.field('name', { multiplier: 10 })
|
||
|
this.field('parent', { multiplier: 5 })
|
||
|
this.field('full_description')
|
||
|
})
|
||
|
|
||
|
var methods = raw.reduce(function (memo, module) {
|
||
|
return memo.concat(module.methods)
|
||
|
}, [])
|
||
|
|
||
|
methods.forEach(function (method) {
|
||
|
idx.add(method)
|
||
|
})
|
||
|
|
||
|
$(document).ready(function () {
|
||
|
|
||
|
var search = function (term) {
|
||
|
return idx.search(term).map(function (id) {
|
||
|
return methods.filter(function (method) {
|
||
|
return method.id === id
|
||
|
})[0]
|
||
|
})
|
||
|
}
|
||
|
|
||
|
var searchResults = $('#search-results')
|
||
|
|
||
|
$('#search-input').keyup(function () {
|
||
|
var query = $(this).val(),
|
||
|
results = search(query)
|
||
|
|
||
|
if (!results.length) {
|
||
|
searchResults.empty()
|
||
|
return
|
||
|
};
|
||
|
|
||
|
var resultsList = results.reduce(function (ul, result) {
|
||
|
var li = $('<li>').append($('<a>', {
|
||
|
href: '#' + result.name,
|
||
|
text: result.name
|
||
|
}))
|
||
|
|
||
|
ul.append(li)
|
||
|
|
||
|
return ul
|
||
|
}, $('<ul>'))
|
||
|
|
||
|
searchResults.html(resultsList)
|
||
|
})
|
||
|
})
|
||
|
</script>
|
||
|
|
||
|
<style type="text/css" media="screen">
|
||
|
body {
|
||
|
font-family: 'Helvetica Neue';
|
||
|
color: #333;
|
||
|
}
|
||
|
|
||
|
a {
|
||
|
color: #0f4bf0;
|
||
|
}
|
||
|
|
||
|
header h1 {
|
||
|
border-top: 4px solid #333;
|
||
|
font-size: 2.6em;
|
||
|
}
|
||
|
|
||
|
header .version {
|
||
|
font-size: 0.6em;
|
||
|
}
|
||
|
|
||
|
.main > header {
|
||
|
margin-bottom: 40px;
|
||
|
}
|
||
|
|
||
|
article {
|
||
|
margin-bottom: 10px;
|
||
|
padding-bottom: 30px;
|
||
|
}
|
||
|
|
||
|
article header h2 {
|
||
|
border-top: 3px solid #333;
|
||
|
font-size: 2em;
|
||
|
padding-top: 5px;
|
||
|
}
|
||
|
|
||
|
article > section {
|
||
|
margin-bottom: 30px;
|
||
|
}
|
||
|
|
||
|
article section h3 {
|
||
|
font-size: 1em;
|
||
|
}
|
||
|
|
||
|
article section header h3 {
|
||
|
padding-top: 2px;
|
||
|
font-size: 1.2em;
|
||
|
margin-bottom: 5px;
|
||
|
border-top: 2px solid #333;
|
||
|
}
|
||
|
|
||
|
article section header h4 {
|
||
|
font-size: 0.9em;
|
||
|
font-family: courier;
|
||
|
margin: 2px 0 5px 0;
|
||
|
}
|
||
|
|
||
|
@-webkit-keyframes highlight {
|
||
|
from {
|
||
|
background-color: #Ffff66;
|
||
|
}
|
||
|
|
||
|
to {
|
||
|
background-color: white;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
section.method:target {
|
||
|
-webkit-animation-duration: 1s;
|
||
|
-webkit-animation-name: highlight;
|
||
|
}
|
||
|
|
||
|
section header .type, section header .related {
|
||
|
margin-top: 0px;
|
||
|
font-size: 0.8em;
|
||
|
}
|
||
|
|
||
|
section.params h4, section.source h4 {
|
||
|
margin-top: 5px;
|
||
|
margin-bottom: 2px;
|
||
|
font-size: 0.9em;
|
||
|
}
|
||
|
|
||
|
section.params ul {
|
||
|
margin-top: 2px;
|
||
|
}
|
||
|
|
||
|
a.show-source {
|
||
|
font-size: 0.8em;
|
||
|
}
|
||
|
|
||
|
.wrap {
|
||
|
width: 960px;
|
||
|
margin: 0 auto;
|
||
|
}
|
||
|
|
||
|
.main {
|
||
|
width: 760px;
|
||
|
float: left;
|
||
|
}
|
||
|
|
||
|
.search {
|
||
|
margin-top: 10px;
|
||
|
float: right;
|
||
|
}
|
||
|
|
||
|
#search-input {
|
||
|
width: 200px;
|
||
|
}
|
||
|
|
||
|
#search-results {
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
#search-results ul {
|
||
|
width: 200px;
|
||
|
position: absolute;
|
||
|
top: 0px;
|
||
|
left: 0px;
|
||
|
background-color: white;
|
||
|
border: 1px solid #ccc;
|
||
|
list-style: none;
|
||
|
padding: 0;
|
||
|
margin-top: 0;
|
||
|
font-size: 0.9em;
|
||
|
}
|
||
|
|
||
|
#search-results li {
|
||
|
padding: 5px;
|
||
|
}
|
||
|
|
||
|
#search-results li:hover {
|
||
|
background-color: #eee;
|
||
|
cursor: pointer;
|
||
|
}
|
||
|
|
||
|
#search-results li a {
|
||
|
text-decoration: none;
|
||
|
width: 200px;
|
||
|
display: block;
|
||
|
}
|
||
|
|
||
|
p {
|
||
|
line-height: 1.4em;
|
||
|
}
|
||
|
|
||
|
nav {
|
||
|
padding-top: 15px;
|
||
|
float: left;
|
||
|
width: 165px;
|
||
|
margin-right: 30px;
|
||
|
text-align: right;
|
||
|
font-size: 0.8em;
|
||
|
}
|
||
|
|
||
|
nav ul {
|
||
|
list-style: none;
|
||
|
margin: 0;
|
||
|
padding: 0;
|
||
|
}
|
||
|
|
||
|
nav ul h3 {
|
||
|
margin-bottom: 5px;
|
||
|
border-top: 2px solid #CCC;
|
||
|
padding-top: 2px;
|
||
|
}
|
||
|
|
||
|
nav ul ul li {
|
||
|
padding: 2px 0;
|
||
|
}
|
||
|
|
||
|
pre {
|
||
|
background-color: rgba(0,0,0,0.1);
|
||
|
padding: 8px;
|
||
|
}
|
||
|
|
||
|
code .keyword, code .special {
|
||
|
font-weight: bold;
|
||
|
color: black;
|
||
|
}
|
||
|
|
||
|
code .string, code .regexp {
|
||
|
color: green
|
||
|
}
|
||
|
|
||
|
code .class {
|
||
|
color: blue
|
||
|
}
|
||
|
|
||
|
code .number {
|
||
|
color: red
|
||
|
}
|
||
|
|
||
|
code .comment {
|
||
|
color: grey;
|
||
|
font-style: italic;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class='wrap'>
|
||
|
|
||
|
|
||
|
<nav>
|
||
|
<ul>
|
||
|
|
||
|
<li>
|
||
|
<a href='#lunr'>
|
||
|
<h3>lunr</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#EventEmitter'>
|
||
|
<h3>EventEmitter</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#addListener'>addListener</a></li>
|
||
|
|
||
|
<li><a href='#removeListener'>removeListener</a></li>
|
||
|
|
||
|
<li><a href='#emit'>emit</a></li>
|
||
|
|
||
|
<li><a href='#hasHandler'>hasHandler</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#tokenizer'>
|
||
|
<h3>tokenizer</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#Pipeline'>
|
||
|
<h3>Pipeline</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#registerFunction'>registerFunction</a></li>
|
||
|
|
||
|
<li><a href='#warnIfFunctionNotRegistered'>warnIfFunctionNotRegistered</a></li>
|
||
|
|
||
|
<li><a href='#load'>load</a></li>
|
||
|
|
||
|
<li><a href='#add'>add</a></li>
|
||
|
|
||
|
<li><a href='#after'>after</a></li>
|
||
|
|
||
|
<li><a href='#before'>before</a></li>
|
||
|
|
||
|
<li><a href='#remove'>remove</a></li>
|
||
|
|
||
|
<li><a href='#run'>run</a></li>
|
||
|
|
||
|
<li><a href='#reset'>reset</a></li>
|
||
|
|
||
|
<li><a href='#toJSON'>toJSON</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#Vector'>
|
||
|
<h3>Vector</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#Node'>Node</a></li>
|
||
|
|
||
|
<li><a href='#magnitude'>magnitude</a></li>
|
||
|
|
||
|
<li><a href='#dot'>dot</a></li>
|
||
|
|
||
|
<li><a href='#similarity'>similarity</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#Node'>
|
||
|
<h3>Node</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#SortedSet'>
|
||
|
<h3>SortedSet</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#load'>load</a></li>
|
||
|
|
||
|
<li><a href='#add'>add</a></li>
|
||
|
|
||
|
<li><a href='#toArray'>toArray</a></li>
|
||
|
|
||
|
<li><a href='#map'>map</a></li>
|
||
|
|
||
|
<li><a href='#forEach'>forEach</a></li>
|
||
|
|
||
|
<li><a href='#indexOf'>indexOf</a></li>
|
||
|
|
||
|
<li><a href='#locationFor'>locationFor</a></li>
|
||
|
|
||
|
<li><a href='#intersect'>intersect</a></li>
|
||
|
|
||
|
<li><a href='#clone'>clone</a></li>
|
||
|
|
||
|
<li><a href='#union'>union</a></li>
|
||
|
|
||
|
<li><a href='#toJSON'>toJSON</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#Index'>
|
||
|
<h3>Index</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#on'>on</a></li>
|
||
|
|
||
|
<li><a href='#off'>off</a></li>
|
||
|
|
||
|
<li><a href='#load'>load</a></li>
|
||
|
|
||
|
<li><a href='#field'>field</a></li>
|
||
|
|
||
|
<li><a href='#ref'>ref</a></li>
|
||
|
|
||
|
<li><a href='#add'>add</a></li>
|
||
|
|
||
|
<li><a href='#remove'>remove</a></li>
|
||
|
|
||
|
<li><a href='#update'>update</a></li>
|
||
|
|
||
|
<li><a href='#idf'>idf</a></li>
|
||
|
|
||
|
<li><a href='#search'>search</a></li>
|
||
|
|
||
|
<li><a href='#documentVector'>documentVector</a></li>
|
||
|
|
||
|
<li><a href='#toJSON'>toJSON</a></li>
|
||
|
|
||
|
<li><a href='#use'>use</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#Store'>
|
||
|
<h3>Store</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#load'>load</a></li>
|
||
|
|
||
|
<li><a href='#set'>set</a></li>
|
||
|
|
||
|
<li><a href='#get'>get</a></li>
|
||
|
|
||
|
<li><a href='#has'>has</a></li>
|
||
|
|
||
|
<li><a href='#remove'>remove</a></li>
|
||
|
|
||
|
<li><a href='#toJSON'>toJSON</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#stemmer'>
|
||
|
<h3>stemmer</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#stopWordFilter'>
|
||
|
<h3>stopWordFilter</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#trimmer'>
|
||
|
<h3>trimmer</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
<a href='#TokenStore'>
|
||
|
<h3>TokenStore</h3>
|
||
|
</a>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li><a href='#load'>load</a></li>
|
||
|
|
||
|
<li><a href='#add'>add</a></li>
|
||
|
|
||
|
<li><a href='#has'>has</a></li>
|
||
|
|
||
|
<li><a href='#getNode'>getNode</a></li>
|
||
|
|
||
|
<li><a href='#get'>get</a></li>
|
||
|
|
||
|
<li><a href='#remove'>remove</a></li>
|
||
|
|
||
|
<li><a href='#expand'>expand</a></li>
|
||
|
|
||
|
<li><a href='#toJSON'>toJSON</a></li>
|
||
|
|
||
|
</ul>
|
||
|
</li>
|
||
|
|
||
|
</ul>
|
||
|
</nav>
|
||
|
|
||
|
<div class='main'>
|
||
|
<header>
|
||
|
<div class='search'>
|
||
|
<input type="search" id="search-input" placeholder="Search"></input>
|
||
|
<div id="search-results"></div>
|
||
|
</div>
|
||
|
<h1>lunr.js <span class='version'>0.5.12</span></h1>
|
||
|
</header>
|
||
|
|
||
|
|
||
|
<article id='lunr'>
|
||
|
<header>
|
||
|
<h2>lunr</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>Convenience function for instantiating a new lunr index and configuring it with the default pipeline functions and the passed config function.</p>
|
||
|
|
||
|
<p>When using this convenience function a new index will be created with the following functions already in the pipeline:</p>
|
||
|
|
||
|
<p>lunr.StopWordFilter - filters out any stop words before they enter the index</p>
|
||
|
|
||
|
<p>lunr.stemmer - stems the tokens before entering the index.</p>
|
||
|
|
||
|
<p>Example:</p>
|
||
|
|
||
|
<pre><code>var idx = lunr(function () {
|
||
|
this.field('title', 10)
|
||
|
this.field('tags', 100)
|
||
|
this.field('body')
|
||
|
|
||
|
this.ref('cid')
|
||
|
|
||
|
this.pipeline.add(function () {
|
||
|
// some custom pipeline function
|
||
|
})
|
||
|
|
||
|
})
|
||
|
</code></pre>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='EventEmitter'>
|
||
|
<header>
|
||
|
<h2>EventEmitter</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers and triggering events and their handlers.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='addListener'>
|
||
|
<header>
|
||
|
<h3>addListener</h3>
|
||
|
<h4>lunr.EventEmitter.prototype.addListener()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>addListener</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>[eventName] - The name(s) of events to bind this function to.</li>
|
||
|
|
||
|
<li>fn - The function to call when an event is fired.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Binds a handler function to a specific event(s).</p>
|
||
|
|
||
|
<p>Can bind a single function to many different events in one call.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.EventEmitter.prototype.addListener = function () {
|
||
|
var args = Array.prototype.slice.call(arguments),
|
||
|
fn = args.pop(),
|
||
|
names = args
|
||
|
|
||
|
if (typeof fn !== "function") throw new TypeError ("last argument must be a function")
|
||
|
|
||
|
names.forEach(function (name) {
|
||
|
if (!this.hasHandler(name)) this.events[name] = []
|
||
|
this.events[name].push(fn)
|
||
|
}, this)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='removeListener'>
|
||
|
<header>
|
||
|
<h3>removeListener</h3>
|
||
|
<h4>lunr.EventEmitter.prototype.removeListener()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>removeListener</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>eventName - The name of the event to remove this function from.</li>
|
||
|
|
||
|
<li>fn - The function to remove from an event.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Removes a handler function from a specific event.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.EventEmitter.prototype.removeListener = function (name, fn) {
|
||
|
if (!this.hasHandler(name)) return
|
||
|
|
||
|
var fnIndex = this.events[name].indexOf(fn)
|
||
|
this.events[name].splice(fnIndex, 1)
|
||
|
|
||
|
if (!this.events[name].length) delete this.events[name]
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='emit'>
|
||
|
<header>
|
||
|
<h3>emit</h3>
|
||
|
<h4>lunr.EventEmitter.prototype.emit()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>emit</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>eventName - The name of the event to emit.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Calls all functions bound to the given event.</p>
|
||
|
|
||
|
<p>Additional data can be passed to the event handler as arguments to <code>emit</code> after the event name.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.EventEmitter.prototype.emit = function (name) {
|
||
|
if (!this.hasHandler(name)) return
|
||
|
|
||
|
var args = Array.prototype.slice.call(arguments, 1)
|
||
|
|
||
|
this.events[name].forEach(function (fn) {
|
||
|
fn.apply(undefined, args)
|
||
|
})
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='hasHandler'>
|
||
|
<header>
|
||
|
<h3>hasHandler</h3>
|
||
|
<h4>lunr.EventEmitter.prototype.hasHandler()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>hasHandler</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>eventName - The name of the event to check.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Checks whether a handler has ever been stored against an event.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.EventEmitter.prototype.hasHandler = function (name) {
|
||
|
return name in this.events
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='tokenizer'>
|
||
|
<header>
|
||
|
<h2>tokenizer</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>A function for splitting a string into tokens ready to be inserted into the search index.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='Pipeline'>
|
||
|
<header>
|
||
|
<h2>Pipeline</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Pipelines maintain an ordered list of functions to be applied to all tokens in documents entering the search index and queries being ran against the index.</p>
|
||
|
|
||
|
<p>An instance of lunr.Index created with the lunr shortcut will contain a pipeline with a stop word filter and an English language stemmer. Extra functions can be added before or after either of these functions or these default functions can be removed.</p>
|
||
|
|
||
|
<p>When run the pipeline will call each function in turn, passing a token, the index of that token in the original list of all tokens and finally a list of all the original tokens.</p>
|
||
|
|
||
|
<p>The output of functions in the pipeline will be passed to the next function in the pipeline. To exclude a token from entering the index the function should return undefined, the rest of the pipeline will not be called with this token.</p>
|
||
|
|
||
|
<p>For serialisation of pipelines to work, all functions used in an instance of a pipeline should be registered with lunr.Pipeline. Registered functions can then be loaded. If trying to load a serialised pipeline that uses functions that are not registered an error will be thrown.</p>
|
||
|
|
||
|
<p>If not planning on serialising the pipeline then registering pipeline functions is not necessary.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='registerFunction'>
|
||
|
<header>
|
||
|
<h3>registerFunction</h3>
|
||
|
<h4>lunr.Pipeline.registerFunction()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>registerFunction</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fn - The function to check for.</li>
|
||
|
|
||
|
<li>label - The label to register this function with</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Register a function with the pipeline.</p>
|
||
|
|
||
|
<p>Functions that are used in the pipeline should be registered if the pipeline needs to be serialised, or a serialised pipeline needs to be loaded.</p>
|
||
|
|
||
|
<p>Registering a function does not add it to a pipeline, functions must still be added to instances of the pipeline for them to be used when running a pipeline.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.registerFunction = function (fn, label) {
|
||
|
if (label in this.registeredFunctions) {
|
||
|
lunr.utils.warn('Overwriting existing registered function: ' + label)
|
||
|
}
|
||
|
|
||
|
fn.label = label
|
||
|
lunr.Pipeline.registeredFunctions[fn.label] = fn
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='warnIfFunctionNotRegistered'>
|
||
|
<header>
|
||
|
<h3>warnIfFunctionNotRegistered</h3>
|
||
|
<h4>lunr.Pipeline.warnIfFunctionNotRegistered()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>warnIfFunctionNotRegistered</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fn - The function to check for.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Warns if the function is not registered as a Pipeline function.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
|
||
|
var isRegistered = fn.label && (fn.label in this.registeredFunctions)
|
||
|
|
||
|
if (!isRegistered) {
|
||
|
lunr.utils.warn('Function is not registered with pipeline. This may cause problems when serialising the index.\n', fn)
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='load'>
|
||
|
<header>
|
||
|
<h3>load</h3>
|
||
|
<h4>lunr.Pipeline.load()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>load</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>serialised - The serialised pipeline to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Loads a previously serialised pipeline.</p>
|
||
|
|
||
|
<p>All functions to be loaded must already be registered with lunr.Pipeline. If any function from the serialised data has not been registered then an error will be thrown.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.load = function (serialised) {
|
||
|
var pipeline = new lunr.Pipeline
|
||
|
|
||
|
serialised.forEach(function (fnName) {
|
||
|
var fn = lunr.Pipeline.registeredFunctions[fnName]
|
||
|
|
||
|
if (fn) {
|
||
|
pipeline.add(fn)
|
||
|
} else {
|
||
|
throw new Error('Cannot load un-registered function: ' + fnName)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return pipeline
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='add'>
|
||
|
<header>
|
||
|
<h3>add</h3>
|
||
|
<h4>lunr.Pipeline.prototype.add()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>add</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>functions - Any number of functions to add to the pipeline.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Adds new functions to the end of the pipeline.</p>
|
||
|
|
||
|
<p>Logs a warning if the function has not been registered.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.add = function () {
|
||
|
var fns = Array.prototype.slice.call(arguments)
|
||
|
|
||
|
fns.forEach(function (fn) {
|
||
|
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
|
||
|
this._stack.push(fn)
|
||
|
}, this)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='after'>
|
||
|
<header>
|
||
|
<h3>after</h3>
|
||
|
<h4>lunr.Pipeline.prototype.after()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>after</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>existingFn - A function that already exists in the pipeline.</li>
|
||
|
|
||
|
<li>newFn - The new function to add to the pipeline.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Adds a single function after a function that already exists in the pipeline.</p>
|
||
|
|
||
|
<p>Logs a warning if the function has not been registered.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.after = function (existingFn, newFn) {
|
||
|
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
|
||
|
|
||
|
var pos = this._stack.indexOf(existingFn)
|
||
|
if (pos == -1) {
|
||
|
throw new Error('Cannot find existingFn')
|
||
|
}
|
||
|
|
||
|
pos = pos + 1
|
||
|
this._stack.splice(pos, 0, newFn)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='before'>
|
||
|
<header>
|
||
|
<h3>before</h3>
|
||
|
<h4>lunr.Pipeline.prototype.before()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>before</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>existingFn - A function that already exists in the pipeline.</li>
|
||
|
|
||
|
<li>newFn - The new function to add to the pipeline.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Adds a single function before a function that already exists in the pipeline.</p>
|
||
|
|
||
|
<p>Logs a warning if the function has not been registered.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.before = function (existingFn, newFn) {
|
||
|
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
|
||
|
|
||
|
var pos = this._stack.indexOf(existingFn)
|
||
|
if (pos == -1) {
|
||
|
throw new Error('Cannot find existingFn')
|
||
|
}
|
||
|
|
||
|
this._stack.splice(pos, 0, newFn)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='remove'>
|
||
|
<header>
|
||
|
<h3>remove</h3>
|
||
|
<h4>lunr.Pipeline.prototype.remove()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>remove</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fn - The function to remove from the pipeline.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Removes a function from the pipeline.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.remove = function (fn) {
|
||
|
var pos = this._stack.indexOf(fn)
|
||
|
if (pos == -1) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
this._stack.splice(pos, 1)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='run'>
|
||
|
<header>
|
||
|
<h3>run</h3>
|
||
|
<h4>lunr.Pipeline.prototype.run()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>run</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>tokens - The tokens to run through the pipeline.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Runs the current list of functions that make up the pipeline against the passed tokens.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.run = function (tokens) {
|
||
|
var out = [],
|
||
|
tokenLength = tokens.length,
|
||
|
stackLength = this._stack.length
|
||
|
|
||
|
for (var i = 0; i < tokenLength; i++) {
|
||
|
var token = tokens[i]
|
||
|
|
||
|
for (var j = 0; j < stackLength; j++) {
|
||
|
token = this._stack[j](token, i, tokens)
|
||
|
if (token === void 0) break
|
||
|
};
|
||
|
|
||
|
if (token !== void 0) out.push(token)
|
||
|
};
|
||
|
|
||
|
return out
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='reset'>
|
||
|
<header>
|
||
|
<h3>reset</h3>
|
||
|
<h4>lunr.Pipeline.prototype.reset()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>reset</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Resets the pipeline by removing any existing processors.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.reset = function () {
|
||
|
this._stack = []
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toJSON'>
|
||
|
<header>
|
||
|
<h3>toJSON</h3>
|
||
|
<h4>lunr.Pipeline.prototype.toJSON()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toJSON</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns a representation of the pipeline ready for serialisation.</p>
|
||
|
|
||
|
<p>Logs a warning if the function has not been registered.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Pipeline.prototype.toJSON = function () {
|
||
|
return this._stack.map(function (fn) {
|
||
|
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
|
||
|
|
||
|
return fn.label
|
||
|
})
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='Vector'>
|
||
|
<header>
|
||
|
<h2>Vector</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Vectors implement vector related operations for a series of elements.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='Node'>
|
||
|
<header>
|
||
|
<h3>Node</h3>
|
||
|
<h4>lunr.Vector.Node()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>Node</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>The - index of the node in the vector.</li>
|
||
|
|
||
|
<li>The - data at this node in the vector.</li>
|
||
|
|
||
|
<li>The - node directly after this node in the vector.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Vector.Node is a simple struct for each node in a lunr.Vector.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Vector.Node = function (idx, val, next) {
|
||
|
this.idx = idx
|
||
|
this.val = val
|
||
|
this.next = next
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='magnitude'>
|
||
|
<header>
|
||
|
<h3>magnitude</h3>
|
||
|
<h4>lunr.Vector.prototype.magnitude()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>magnitude</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Calculates the magnitude of this vector.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Vector.prototype.magnitude = function () {
|
||
|
if (this._magnitude) return this._magnitude
|
||
|
var node = this.list,
|
||
|
sumOfSquares = 0,
|
||
|
val
|
||
|
|
||
|
while (node) {
|
||
|
val = node.val
|
||
|
sumOfSquares += val * val
|
||
|
node = node.next
|
||
|
}
|
||
|
|
||
|
return this._magnitude = Math.sqrt(sumOfSquares)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='dot'>
|
||
|
<header>
|
||
|
<h3>dot</h3>
|
||
|
<h4>lunr.Vector.prototype.dot()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>dot</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>otherVector - The vector to compute the dot product with.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Calculates the dot product of this vector and another vector.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Vector.prototype.dot = function (otherVector) {
|
||
|
var node = this.list,
|
||
|
otherNode = otherVector.list,
|
||
|
dotProduct = 0
|
||
|
|
||
|
while (node && otherNode) {
|
||
|
if (node.idx < otherNode.idx) {
|
||
|
node = node.next
|
||
|
} else if (node.idx > otherNode.idx) {
|
||
|
otherNode = otherNode.next
|
||
|
} else {
|
||
|
dotProduct += node.val * otherNode.val
|
||
|
node = node.next
|
||
|
otherNode = otherNode.next
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return dotProduct
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='similarity'>
|
||
|
<header>
|
||
|
<h3>similarity</h3>
|
||
|
<h4>lunr.Vector.prototype.similarity()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>similarity</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>otherVector - The other vector to calculate the</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Calculates the cosine similarity between this vector and another vector.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Vector.prototype.similarity = function (otherVector) {
|
||
|
return this.dot(otherVector) / (this.magnitude() * otherVector.magnitude())
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='Node'>
|
||
|
<header>
|
||
|
<h2>Node</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Vector.Node is a simple struct for each node in a lunr.Vector.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='SortedSet'>
|
||
|
<header>
|
||
|
<h2>SortedSet</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.SortedSets are used to maintain an array of uniq values in a sorted order.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='load'>
|
||
|
<header>
|
||
|
<h3>load</h3>
|
||
|
<h4>lunr.SortedSet.load()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>load</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>serialisedData - The serialised set to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Loads a previously serialised sorted set.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.load = function (serialisedData) {
|
||
|
var set = new this
|
||
|
|
||
|
set.elements = serialisedData
|
||
|
set.length = serialisedData.length
|
||
|
|
||
|
return set
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='add'>
|
||
|
<header>
|
||
|
<h3>add</h3>
|
||
|
<h4>lunr.SortedSet.prototype.add()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>add</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>The - objects to add to this set.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Inserts new items into the set in the correct position to maintain the order.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.add = function () {
|
||
|
var i, element
|
||
|
|
||
|
for (i = 0; i < arguments.length; i++) {
|
||
|
element = arguments[i]
|
||
|
if (~this.indexOf(element)) continue
|
||
|
this.elements.splice(this.locationFor(element), 0, element)
|
||
|
}
|
||
|
|
||
|
this.length = this.elements.length
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toArray'>
|
||
|
<header>
|
||
|
<h3>toArray</h3>
|
||
|
<h4>lunr.SortedSet.prototype.toArray()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toArray</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Converts this sorted set into an array.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.toArray = function () {
|
||
|
return this.elements.slice()
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='map'>
|
||
|
<header>
|
||
|
<h3>map</h3>
|
||
|
<h4>lunr.SortedSet.prototype.map()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>map</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fn - The function that is called on each element of the</li>
|
||
|
|
||
|
<li>ctx - An optional object that can be used as the context</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Creates a new array with the results of calling a provided function on every element in this sorted set.</p>
|
||
|
|
||
|
<p>Delegates to Array.prototype.map and has the same signature.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.map = function (fn, ctx) {
|
||
|
return this.elements.map(fn, ctx)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='forEach'>
|
||
|
<header>
|
||
|
<h3>forEach</h3>
|
||
|
<h4>lunr.SortedSet.prototype.forEach()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>forEach</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fn - The function that is called on each element of the</li>
|
||
|
|
||
|
<li>ctx - An optional object that can be used as the context</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Executes a provided function once per sorted set element.</p>
|
||
|
|
||
|
<p>Delegates to Array.prototype.forEach and has the same signature.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.forEach = function (fn, ctx) {
|
||
|
return this.elements.forEach(fn, ctx)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='indexOf'>
|
||
|
<header>
|
||
|
<h3>indexOf</h3>
|
||
|
<h4>lunr.SortedSet.prototype.indexOf()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>indexOf</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>elem - The object to locate in the sorted set.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns the index at which a given element can be found in the sorted set, or -1 if it is not present.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.indexOf = function (elem) {
|
||
|
var start = 0,
|
||
|
end = this.elements.length,
|
||
|
sectionLength = end - start,
|
||
|
pivot = start + Math.floor(sectionLength / 2),
|
||
|
pivotElem = this.elements[pivot]
|
||
|
|
||
|
while (sectionLength > 1) {
|
||
|
if (pivotElem === elem) return pivot
|
||
|
|
||
|
if (pivotElem < elem) start = pivot
|
||
|
if (pivotElem > elem) end = pivot
|
||
|
|
||
|
sectionLength = end - start
|
||
|
pivot = start + Math.floor(sectionLength / 2)
|
||
|
pivotElem = this.elements[pivot]
|
||
|
}
|
||
|
|
||
|
if (pivotElem === elem) return pivot
|
||
|
|
||
|
return -1
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='locationFor'>
|
||
|
<header>
|
||
|
<h3>locationFor</h3>
|
||
|
<h4>lunr.SortedSet.prototype.locationFor()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>locationFor</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>elem - The elem to find the position for in the set</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns the position within the sorted set that an element should be inserted at to maintain the current order of the set.</p>
|
||
|
|
||
|
<p>This function assumes that the element to search for does not already exist in the sorted set.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.locationFor = function (elem) {
|
||
|
var start = 0,
|
||
|
end = this.elements.length,
|
||
|
sectionLength = end - start,
|
||
|
pivot = start + Math.floor(sectionLength / 2),
|
||
|
pivotElem = this.elements[pivot]
|
||
|
|
||
|
while (sectionLength > 1) {
|
||
|
if (pivotElem < elem) start = pivot
|
||
|
if (pivotElem > elem) end = pivot
|
||
|
|
||
|
sectionLength = end - start
|
||
|
pivot = start + Math.floor(sectionLength / 2)
|
||
|
pivotElem = this.elements[pivot]
|
||
|
}
|
||
|
|
||
|
if (pivotElem > elem) return pivot
|
||
|
if (pivotElem < elem) return pivot + 1
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='intersect'>
|
||
|
<header>
|
||
|
<h3>intersect</h3>
|
||
|
<h4>lunr.SortedSet.prototype.intersect()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>intersect</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>otherSet - The set to intersect with this set.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Creates a new lunr.SortedSet that contains the elements in the intersection of this set and the passed set.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.intersect = function (otherSet) {
|
||
|
var intersectSet = new lunr.SortedSet,
|
||
|
i = 0, j = 0,
|
||
|
a_len = this.length, b_len = otherSet.length,
|
||
|
a = this.elements, b = otherSet.elements
|
||
|
|
||
|
while (true) {
|
||
|
if (i > a_len - 1 || j > b_len - 1) break
|
||
|
|
||
|
if (a[i] === b[j]) {
|
||
|
intersectSet.add(a[i])
|
||
|
i++, j++
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if (a[i] < b[j]) {
|
||
|
i++
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if (a[i] > b[j]) {
|
||
|
j++
|
||
|
continue
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return intersectSet
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='clone'>
|
||
|
<header>
|
||
|
<h3>clone</h3>
|
||
|
<h4>lunr.SortedSet.prototype.clone()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>clone</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Makes a copy of this set</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.clone = function () {
|
||
|
var clone = new lunr.SortedSet
|
||
|
|
||
|
clone.elements = this.toArray()
|
||
|
clone.length = clone.elements.length
|
||
|
|
||
|
return clone
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='union'>
|
||
|
<header>
|
||
|
<h3>union</h3>
|
||
|
<h4>lunr.SortedSet.prototype.union()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>union</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>otherSet - The set to union with this set.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Creates a new lunr.SortedSet that contains the elements in the union of this set and the passed set.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.union = function (otherSet) {
|
||
|
var longSet, shortSet, unionSet
|
||
|
|
||
|
if (this.length >= otherSet.length) {
|
||
|
longSet = this, shortSet = otherSet
|
||
|
} else {
|
||
|
longSet = otherSet, shortSet = this
|
||
|
}
|
||
|
|
||
|
unionSet = longSet.clone()
|
||
|
|
||
|
unionSet.add.apply(unionSet, shortSet.toArray())
|
||
|
|
||
|
return unionSet
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toJSON'>
|
||
|
<header>
|
||
|
<h3>toJSON</h3>
|
||
|
<h4>lunr.SortedSet.prototype.toJSON()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toJSON</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns a representation of the sorted set ready for serialisation.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.SortedSet.prototype.toJSON = function () {
|
||
|
return this.toArray()
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='Index'>
|
||
|
<header>
|
||
|
<h2>Index</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Index is object that manages a search index. It contains the indexes and stores all the tokens and document lookups. It also provides the main user facing API for the library.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='on'>
|
||
|
<header>
|
||
|
<h3>on</h3>
|
||
|
<h4>lunr.Index.prototype.on()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>on</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>[eventName] - The name(s) of events to bind the function to.</li>
|
||
|
|
||
|
<li>fn - The serialised set to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Bind a handler to events being emitted by the index.</p>
|
||
|
|
||
|
<p>The handler can be bound to many events at the same time.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.on = function () {
|
||
|
var args = Array.prototype.slice.call(arguments)
|
||
|
return this.eventEmitter.addListener.apply(this.eventEmitter, args)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='off'>
|
||
|
<header>
|
||
|
<h3>off</h3>
|
||
|
<h4>lunr.Index.prototype.off()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>off</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>eventName - The name of events to remove the function from.</li>
|
||
|
|
||
|
<li>fn - The serialised set to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Removes a handler from an event being emitted by the index.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.off = function (name, fn) {
|
||
|
return this.eventEmitter.removeListener(name, fn)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='load'>
|
||
|
<header>
|
||
|
<h3>load</h3>
|
||
|
<h4>lunr.Index.load()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>load</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>serialisedData - The serialised set to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Loads a previously serialised index.</p>
|
||
|
|
||
|
<p>Issues a warning if the index being imported was serialised by a different version of lunr.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.load = function (serialisedData) {
|
||
|
if (serialisedData.version !== lunr.version) {
|
||
|
lunr.utils.warn('version mismatch: current ' + lunr.version + ' importing ' + serialisedData.version)
|
||
|
}
|
||
|
|
||
|
var idx = new this
|
||
|
|
||
|
idx._fields = serialisedData.fields
|
||
|
idx._ref = serialisedData.ref
|
||
|
|
||
|
idx.documentStore = lunr.Store.load(serialisedData.documentStore)
|
||
|
idx.tokenStore = lunr.TokenStore.load(serialisedData.tokenStore)
|
||
|
idx.corpusTokens = lunr.SortedSet.load(serialisedData.corpusTokens)
|
||
|
idx.pipeline = lunr.Pipeline.load(serialisedData.pipeline)
|
||
|
|
||
|
return idx
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='field'>
|
||
|
<header>
|
||
|
<h3>field</h3>
|
||
|
<h4>lunr.Index.prototype.field()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>field</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>fieldName - The name of the field within the document that</li>
|
||
|
|
||
|
<li>boost - An optional boost that can be applied to terms in this</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Adds a field to the list of fields that will be searchable within documents in the index.</p>
|
||
|
|
||
|
<p>An optional boost param can be passed to affect how much tokens in this field rank in search results, by default the boost value is 1.</p>
|
||
|
|
||
|
<p>Fields should be added before any documents are added to the index, fields that are added after documents are added to the index will only apply to new documents added to the index.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.field = function (fieldName, opts) {
|
||
|
var opts = opts || {},
|
||
|
field = { name: fieldName, boost: opts.boost || 1 }
|
||
|
|
||
|
this._fields.push(field)
|
||
|
return this
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='ref'>
|
||
|
<header>
|
||
|
<h3>ref</h3>
|
||
|
<h4>lunr.Index.prototype.ref()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>ref</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>refName - The property to use to uniquely identify the</li>
|
||
|
|
||
|
<li>emitEvent - Whether to emit add events, defaults to true</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Sets the property used to uniquely identify documents added to the index, by default this property is 'id'.</p>
|
||
|
|
||
|
<p>This should only be changed before adding documents to the index, changing the ref property without resetting the index can lead to unexpected results.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.ref = function (refName) {
|
||
|
this._ref = refName
|
||
|
return this
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='add'>
|
||
|
<header>
|
||
|
<h3>add</h3>
|
||
|
<h4>lunr.Index.prototype.add()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>add</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>doc - The document to add to the index.</li>
|
||
|
|
||
|
<li>emitEvent - Whether or not to emit events, default true.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Add a document to the index.</p>
|
||
|
|
||
|
<p>This is the way new documents enter the index, this function will run the fields from the document through the index's pipeline and then add it to the index, it will then show up in search results.</p>
|
||
|
|
||
|
<p>An 'add' event is emitted with the document that has been added and the index the document has been added to. This event can be silenced by passing false as the second argument to add.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.add = function (doc, emitEvent) {
|
||
|
var docTokens = {},
|
||
|
allDocumentTokens = new lunr.SortedSet,
|
||
|
docRef = doc[this._ref],
|
||
|
emitEvent = emitEvent === undefined ? true : emitEvent
|
||
|
|
||
|
this._fields.forEach(function (field) {
|
||
|
var fieldTokens = this.pipeline.run(lunr.tokenizer(doc[field.name]))
|
||
|
|
||
|
docTokens[field.name] = fieldTokens
|
||
|
lunr.SortedSet.prototype.add.apply(allDocumentTokens, fieldTokens)
|
||
|
}, this)
|
||
|
|
||
|
this.documentStore.set(docRef, allDocumentTokens)
|
||
|
lunr.SortedSet.prototype.add.apply(this.corpusTokens, allDocumentTokens.toArray())
|
||
|
|
||
|
for (var i = 0; i < allDocumentTokens.length; i++) {
|
||
|
var token = allDocumentTokens.elements[i]
|
||
|
var tf = this._fields.reduce(function (memo, field) {
|
||
|
var fieldLength = docTokens[field.name].length
|
||
|
|
||
|
if (!fieldLength) return memo
|
||
|
|
||
|
var tokenCount = docTokens[field.name].filter(function (t) { return t === token }).length
|
||
|
|
||
|
return memo + (tokenCount / fieldLength * field.boost)
|
||
|
}, 0)
|
||
|
|
||
|
this.tokenStore.add(token, { ref: docRef, tf: tf })
|
||
|
};
|
||
|
|
||
|
if (emitEvent) this.eventEmitter.emit('add', doc, this)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='remove'>
|
||
|
<header>
|
||
|
<h3>remove</h3>
|
||
|
<h4>lunr.Index.prototype.remove()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>remove</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>doc - The document to remove from the index.</li>
|
||
|
|
||
|
<li>emitEvent - Whether to emit remove events, defaults to true</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Removes a document from the index.</p>
|
||
|
|
||
|
<p>To make sure documents no longer show up in search results they can be removed from the index using this method.</p>
|
||
|
|
||
|
<p>The document passed only needs to have the same ref property value as the document that was added to the index, they could be completely different objects.</p>
|
||
|
|
||
|
<p>A 'remove' event is emitted with the document that has been removed and the index the document has been removed from. This event can be silenced by passing false as the second argument to remove.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.remove = function (doc, emitEvent) {
|
||
|
var docRef = doc[this._ref],
|
||
|
emitEvent = emitEvent === undefined ? true : emitEvent
|
||
|
|
||
|
if (!this.documentStore.has(docRef)) return
|
||
|
|
||
|
var docTokens = this.documentStore.get(docRef)
|
||
|
|
||
|
this.documentStore.remove(docRef)
|
||
|
|
||
|
docTokens.forEach(function (token) {
|
||
|
this.tokenStore.remove(token, docRef)
|
||
|
}, this)
|
||
|
|
||
|
if (emitEvent) this.eventEmitter.emit('remove', doc, this)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='update'>
|
||
|
<header>
|
||
|
<h3>update</h3>
|
||
|
<h4>lunr.Index.prototype.update()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>update</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>doc - The document to update in the index.</li>
|
||
|
|
||
|
<li>emitEvent - Whether to emit update events, defaults to true</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Updates a document in the index.</p>
|
||
|
|
||
|
<p>When a document contained within the index gets updated, fields changed, added or removed, to make sure it correctly matched against search queries, it should be updated in the index.</p>
|
||
|
|
||
|
<p>This method is just a wrapper around <code>remove</code> and <code>add</code></p>
|
||
|
|
||
|
<p>An 'update' event is emitted with the document that has been updated and the index. This event can be silenced by passing false as the second argument to update. Only an update event will be fired, the 'add' and 'remove' events of the underlying calls are silenced.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.update = function (doc, emitEvent) {
|
||
|
var emitEvent = emitEvent === undefined ? true : emitEvent
|
||
|
|
||
|
this.remove(doc, false)
|
||
|
this.add(doc, false)
|
||
|
|
||
|
if (emitEvent) this.eventEmitter.emit('update', doc, this)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='idf'>
|
||
|
<header>
|
||
|
<h3>idf</h3>
|
||
|
<h4>lunr.Index.prototype.idf()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>idf</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to calculate the idf of.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Calculates the inverse document frequency for a token within the index.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.idf = function (term) {
|
||
|
var cacheKey = "@" + term
|
||
|
if (Object.prototype.hasOwnProperty.call(this._idfCache, cacheKey)) return this._idfCache[cacheKey]
|
||
|
|
||
|
var documentFrequency = this.tokenStore.count(term),
|
||
|
idf = 1
|
||
|
|
||
|
if (documentFrequency > 0) {
|
||
|
idf = 1 + Math.log(this.documentStore.length / documentFrequency)
|
||
|
}
|
||
|
|
||
|
return this._idfCache[cacheKey] = idf
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='search'>
|
||
|
<header>
|
||
|
<h3>search</h3>
|
||
|
<h4>lunr.Index.prototype.search()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>search</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>query - The query to search the index with.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Searches the index using the passed query.</p>
|
||
|
|
||
|
<p>Queries should be a string, multiple words are allowed and will lead to an AND based query, e.g. <code>idx.search('foo bar')</code> will run a search for documents containing both 'foo' and 'bar'.</p>
|
||
|
|
||
|
<p>All query tokens are passed through the same pipeline that document tokens are passed through, so any language processing involved will be run on every query term.</p>
|
||
|
|
||
|
<p>Each query term is expanded, so that the term 'he' might be expanded to 'hello' and 'help' if those terms were already included in the index.</p>
|
||
|
|
||
|
<p>Matching documents are returned as an array of objects, each object contains the matching document ref, as set for this index, and the similarity score for this document against the query.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.search = function (query) {
|
||
|
var queryTokens = this.pipeline.run(lunr.tokenizer(query)),
|
||
|
queryVector = new lunr.Vector,
|
||
|
documentSets = [],
|
||
|
fieldBoosts = this._fields.reduce(function (memo, f) { return memo + f.boost }, 0)
|
||
|
|
||
|
var hasSomeToken = queryTokens.some(function (token) {
|
||
|
return this.tokenStore.has(token)
|
||
|
}, this)
|
||
|
|
||
|
if (!hasSomeToken) return []
|
||
|
|
||
|
queryTokens
|
||
|
.forEach(function (token, i, tokens) {
|
||
|
var tf = 1 / tokens.length * this._fields.length * fieldBoosts,
|
||
|
self = this
|
||
|
|
||
|
var set = this.tokenStore.expand(token).reduce(function (memo, key) {
|
||
|
var pos = self.corpusTokens.indexOf(key),
|
||
|
idf = self.idf(key),
|
||
|
similarityBoost = 1,
|
||
|
set = new lunr.SortedSet
|
||
|
|
||
|
// if the expanded key is not an exact match to the token then
|
||
|
// penalise the score for this key by how different the key is
|
||
|
// to the token.
|
||
|
if (key !== token) {
|
||
|
var diff = Math.max(3, key.length - token.length)
|
||
|
similarityBoost = 1 / Math.log(diff)
|
||
|
}
|
||
|
|
||
|
// calculate the query tf-idf score for this token
|
||
|
// applying an similarityBoost to ensure exact matches
|
||
|
// these rank higher than expanded terms
|
||
|
if (pos > -1) queryVector.insert(pos, tf * idf * similarityBoost)
|
||
|
|
||
|
// add all the documents that have this key into a set
|
||
|
Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref) })
|
||
|
|
||
|
return memo.union(set)
|
||
|
}, new lunr.SortedSet)
|
||
|
|
||
|
documentSets.push(set)
|
||
|
}, this)
|
||
|
|
||
|
var documentSet = documentSets.reduce(function (memo, set) {
|
||
|
return memo.intersect(set)
|
||
|
})
|
||
|
|
||
|
return documentSet
|
||
|
.map(function (ref) {
|
||
|
return { ref: ref, score: queryVector.similarity(this.documentVector(ref)) }
|
||
|
}, this)
|
||
|
.sort(function (a, b) {
|
||
|
return b.score - a.score
|
||
|
})
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='documentVector'>
|
||
|
<header>
|
||
|
<h3>documentVector</h3>
|
||
|
<h4>lunr.Index.prototype.documentVector()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>documentVector</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>documentRef - The ref to find the document with.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Generates a vector containing all the tokens in the document matching the passed documentRef.</p>
|
||
|
|
||
|
<p>The vector contains the tf-idf score for each token contained in the document with the passed documentRef. The vector will contain an element for every token in the indexes corpus, if the document does not contain that token the element will be 0.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.documentVector = function (documentRef) {
|
||
|
var documentTokens = this.documentStore.get(documentRef),
|
||
|
documentTokensLength = documentTokens.length,
|
||
|
documentVector = new lunr.Vector
|
||
|
|
||
|
for (var i = 0; i < documentTokensLength; i++) {
|
||
|
var token = documentTokens.elements[i],
|
||
|
tf = this.tokenStore.get(token)[documentRef].tf,
|
||
|
idf = this.idf(token)
|
||
|
|
||
|
documentVector.insert(this.corpusTokens.indexOf(token), tf * idf)
|
||
|
};
|
||
|
|
||
|
return documentVector
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toJSON'>
|
||
|
<header>
|
||
|
<h3>toJSON</h3>
|
||
|
<h4>lunr.Index.prototype.toJSON()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toJSON</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns a representation of the index ready for serialisation.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.toJSON = function () {
|
||
|
return {
|
||
|
version: lunr.version,
|
||
|
fields: this._fields,
|
||
|
ref: this._ref,
|
||
|
documentStore: this.documentStore.toJSON(),
|
||
|
tokenStore: this.tokenStore.toJSON(),
|
||
|
corpusTokens: this.corpusTokens.toJSON(),
|
||
|
pipeline: this.pipeline.toJSON()
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='use'>
|
||
|
<header>
|
||
|
<h3>use</h3>
|
||
|
<h4>lunr.Index.prototype.use()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>use</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>plugin - The plugin to apply.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Applies a plugin to the current index.</p>
|
||
|
|
||
|
<p>A plugin is a function that is called with the index as its context. Plugins can be used to customise or extend the behaviour the index in some way. A plugin is just a function, that encapsulated the custom behaviour that should be applied to the index.</p>
|
||
|
|
||
|
<p>The plugin function will be called with the index as its argument, additional arguments can also be passed when calling use. The function will be called with the index as its context.</p>
|
||
|
|
||
|
<p>Example:</p>
|
||
|
|
||
|
<pre><code>var myPlugin = function (idx, arg1, arg2) {
|
||
|
// `this` is the index to be extended
|
||
|
// apply any extensions etc here.
|
||
|
}
|
||
|
|
||
|
var idx = lunr(function () {
|
||
|
this.use(myPlugin, 'arg1', 'arg2')
|
||
|
})
|
||
|
</code></pre>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Index.prototype.use = function (plugin) {
|
||
|
var args = Array.prototype.slice.call(arguments, 1)
|
||
|
args.unshift(this)
|
||
|
plugin.apply(this, args)
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='Store'>
|
||
|
<header>
|
||
|
<h2>Store</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.Store is a simple key-value store used for storing sets of tokens for documents stored in index.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='load'>
|
||
|
<header>
|
||
|
<h3>load</h3>
|
||
|
<h4>lunr.Store.load()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>load</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>serialisedData - The serialised store to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Loads a previously serialised store</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.load = function (serialisedData) {
|
||
|
var store = new this
|
||
|
|
||
|
store.length = serialisedData.length
|
||
|
store.store = Object.keys(serialisedData.store).reduce(function (memo, key) {
|
||
|
memo[key] = lunr.SortedSet.load(serialisedData.store[key])
|
||
|
return memo
|
||
|
}, {})
|
||
|
|
||
|
return store
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='set'>
|
||
|
<header>
|
||
|
<h3>set</h3>
|
||
|
<h4>lunr.Store.prototype.set()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>set</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>id - The key used to store the tokens against.</li>
|
||
|
|
||
|
<li>tokens - The tokens to store against the key.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Stores the given tokens in the store against the given id.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.prototype.set = function (id, tokens) {
|
||
|
if (!this.has(id)) this.length++
|
||
|
this.store[id] = tokens
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='get'>
|
||
|
<header>
|
||
|
<h3>get</h3>
|
||
|
<h4>lunr.Store.prototype.get()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>get</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>id - The key to lookup and retrieve from the store.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Retrieves the tokens from the store for a given key.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.prototype.get = function (id) {
|
||
|
return this.store[id]
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='has'>
|
||
|
<header>
|
||
|
<h3>has</h3>
|
||
|
<h4>lunr.Store.prototype.has()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>has</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>id - The id to look up in the store.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Checks whether the store contains a key.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.prototype.has = function (id) {
|
||
|
return id in this.store
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='remove'>
|
||
|
<header>
|
||
|
<h3>remove</h3>
|
||
|
<h4>lunr.Store.prototype.remove()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>remove</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>id - The id to remove from the store.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Removes the value for a key in the store.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.prototype.remove = function (id) {
|
||
|
if (!this.has(id)) return
|
||
|
|
||
|
delete this.store[id]
|
||
|
this.length--
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toJSON'>
|
||
|
<header>
|
||
|
<h3>toJSON</h3>
|
||
|
<h4>lunr.Store.prototype.toJSON()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toJSON</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns a representation of the store ready for serialisation.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.Store.prototype.toJSON = function () {
|
||
|
return {
|
||
|
store: this.store,
|
||
|
length: this.length
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='stemmer'>
|
||
|
<header>
|
||
|
<h2>stemmer</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.stemmer is an english language stemmer, this is a JavaScript implementation of the PorterStemmer taken from <a href='http://tartarus.org/~martin'>http://tartarus.org/~martin</a></p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='stopWordFilter'>
|
||
|
<header>
|
||
|
<h2>stopWordFilter</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.stopWordFilter is an English language stop word list filter, any words contained in the list will not be passed through the filter.</p>
|
||
|
|
||
|
<p>This is intended to be used in the Pipeline. If the token does not pass the filter then undefined will be returned.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='trimmer'>
|
||
|
<header>
|
||
|
<h2>trimmer</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.trimmer is a pipeline function for trimming non word characters from the begining and end of tokens before they enter the index.</p>
|
||
|
|
||
|
<p>This implementation may not work correctly for non latin characters and should either be removed or adapted for use with languages with non-latin characters.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</article>
|
||
|
|
||
|
<article id='TokenStore'>
|
||
|
<header>
|
||
|
<h2>TokenStore</h2>
|
||
|
</header>
|
||
|
|
||
|
<section>
|
||
|
<p>lunr.TokenStore is used for efficient storing and lookup of the reverse index of token to document ref.</p>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
<section class='method' id='load'>
|
||
|
<header>
|
||
|
<h3>load</h3>
|
||
|
<h4>lunr.TokenStore.load()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>load</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>serialisedData - The serialised token store to load.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Loads a previously serialised token store</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.load = function (serialisedData) {
|
||
|
var store = new this
|
||
|
|
||
|
store.root = serialisedData.root
|
||
|
store.length = serialisedData.length
|
||
|
|
||
|
return store
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='add'>
|
||
|
<header>
|
||
|
<h3>add</h3>
|
||
|
<h4>lunr.TokenStore.prototype.add()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>add</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to store the doc under</li>
|
||
|
|
||
|
<li>doc - The doc to store against the token</li>
|
||
|
|
||
|
<li>root - An optional node at which to start looking for the</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Adds a new token doc pair to the store.</p>
|
||
|
|
||
|
<p>By default this function starts at the root of the current store, however it can start at any node of any token store if required.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.add = function (token, doc, root) {
|
||
|
var root = root || this.root,
|
||
|
key = token[0],
|
||
|
rest = token.slice(1)
|
||
|
|
||
|
if (!(key in root)) root[key] = {docs: {}}
|
||
|
|
||
|
if (rest.length === 0) {
|
||
|
root[key].docs[doc.ref] = doc
|
||
|
this.length += 1
|
||
|
return
|
||
|
} else {
|
||
|
return this.add(rest, doc, root[key])
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='has'>
|
||
|
<header>
|
||
|
<h3>has</h3>
|
||
|
<h4>lunr.TokenStore.prototype.has()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>has</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to check for</li>
|
||
|
|
||
|
<li>root - An optional node at which to start</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Checks whether this key is contained within this lunr.TokenStore.</p>
|
||
|
|
||
|
<p>By default this function starts at the root of the current store, however it can start at any node of any token store if required.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.has = function (token) {
|
||
|
if (!token) return false
|
||
|
|
||
|
var node = this.root
|
||
|
|
||
|
for (var i = 0; i < token.length; i++) {
|
||
|
if (!node[token[i]]) return false
|
||
|
|
||
|
node = node[token[i]]
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='getNode'>
|
||
|
<header>
|
||
|
<h3>getNode</h3>
|
||
|
<h4>lunr.TokenStore.prototype.getNode()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>getNode</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to get the node for.</li>
|
||
|
|
||
|
<li>root - An optional node at which to start.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Retrieve a node from the token store for a given token.</p>
|
||
|
|
||
|
<p>By default this function starts at the root of the current store, however it can start at any node of any token store if required.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.getNode = function (token) {
|
||
|
if (!token) return {}
|
||
|
|
||
|
var node = this.root
|
||
|
|
||
|
for (var i = 0; i < token.length; i++) {
|
||
|
if (!node[token[i]]) return {}
|
||
|
|
||
|
node = node[token[i]]
|
||
|
}
|
||
|
|
||
|
return node
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='get'>
|
||
|
<header>
|
||
|
<h3>get</h3>
|
||
|
<h4>lunr.TokenStore.prototype.get()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>get</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to get the documents for.</li>
|
||
|
|
||
|
<li>root - An optional node at which to start.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Retrieve the documents for a node for the given token.</p>
|
||
|
|
||
|
<p>By default this function starts at the root of the current store, however it can start at any node of any token store if required.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.get = function (token, root) {
|
||
|
return this.getNode(token, root).docs || {}
|
||
|
}
|
||
|
|
||
|
lunr.TokenStore.prototype.count = function (token, root) {
|
||
|
return Object.keys(this.get(token, root)).length
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='remove'>
|
||
|
<header>
|
||
|
<h3>remove</h3>
|
||
|
<h4>lunr.TokenStore.prototype.remove()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>remove</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to get the documents for.</li>
|
||
|
|
||
|
<li>ref - The ref of the document to remove from this token.</li>
|
||
|
|
||
|
<li>root - An optional node at which to start.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Remove the document identified by ref from the token in the store.</p>
|
||
|
|
||
|
<p>By default this function starts at the root of the current store, however it can start at any node of any token store if required.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.remove = function (token, ref) {
|
||
|
if (!token) return
|
||
|
var node = this.root
|
||
|
|
||
|
for (var i = 0; i < token.length; i++) {
|
||
|
if (!(token[i] in node)) return
|
||
|
node = node[token[i]]
|
||
|
}
|
||
|
|
||
|
delete node.docs[ref]
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='expand'>
|
||
|
<header>
|
||
|
<h3>expand</h3>
|
||
|
<h4>lunr.TokenStore.prototype.expand()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>expand</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<h4>Params</h4>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>token - The token to expand.</li>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Find all the possible suffixes of the passed token using tokens currently in the store.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.expand = function (token, memo) {
|
||
|
var root = this.getNode(token),
|
||
|
docs = root.docs || {},
|
||
|
memo = memo || []
|
||
|
|
||
|
if (Object.keys(docs).length) memo.push(token)
|
||
|
|
||
|
Object.keys(root)
|
||
|
.forEach(function (key) {
|
||
|
if (key === 'docs') return
|
||
|
|
||
|
memo.concat(this.expand(token + key, memo))
|
||
|
}, this)
|
||
|
|
||
|
return memo
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
<section class='method' id='toJSON'>
|
||
|
<header>
|
||
|
<h3>toJSON</h3>
|
||
|
<h4>lunr.TokenStore.prototype.toJSON()</h4>
|
||
|
<p class='type'>method</p>
|
||
|
|
||
|
<p class='related'>See: <a href='#'>toJSON</a></p>
|
||
|
|
||
|
</header>
|
||
|
|
||
|
<section class='params'>
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
</ul>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<p>Returns a representation of the token store ready for serialisation.</p>
|
||
|
</section>
|
||
|
|
||
|
<section class='source'>
|
||
|
<h4>Source</h4>
|
||
|
<pre><code>lunr.TokenStore.prototype.toJSON = function () {
|
||
|
return {
|
||
|
root: this.root,
|
||
|
length: this.length
|
||
|
}
|
||
|
}</code></pre>
|
||
|
</section>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<script>
|
||
|
(function (hijs) {
|
||
|
//
|
||
|
// hijs - JavaScript Syntax Highlighter
|
||
|
//
|
||
|
// Copyright (c) 2010 Alexis Sellier
|
||
|
//
|
||
|
|
||
|
// All elements which match this will be syntax highlighted.
|
||
|
var selector = hijs || 'code';
|
||
|
|
||
|
var keywords = ('var function if else for while break switch case do new null in with void '
|
||
|
+'continue delete return this true false throw catch typeof with instanceof').split(' '),
|
||
|
special = ('eval window document undefined NaN Infinity parseInt parseFloat '
|
||
|
+'encodeURI decodeURI encodeURIComponent decodeURIComponent').split(' ');
|
||
|
|
||
|
// Syntax definition
|
||
|
// The key becomes the class name of the <span>
|
||
|
// around the matched block of code.
|
||
|
var syntax = [
|
||
|
['comment', /(\/\*(?:[^*\n]|\*+[^\/*])*\*+\/)/g],
|
||
|
['comment', /(\/\/[^\n]*)/g],
|
||
|
['string' , /("(?:(?!")[^\\\n]|\\.)*"|'(?:(?!')[^\\\n]|\\.)*')/g],
|
||
|
['regexp' , /(\/.+\/[mgi]*)(?!\s*\w)/g],
|
||
|
['class' , /\b([A-Z][a-zA-Z]+)\b/g],
|
||
|
['number' , /\b([0-9]+(?:\.[0-9]+)?)\b/g],
|
||
|
['keyword', new(RegExp)('\\b(' + keywords.join('|') + ')\\b', 'g')],
|
||
|
['special', new(RegExp)('\\b(' + special.join('|') + ')\\b', 'g')]
|
||
|
];
|
||
|
var nodes, table = {};
|
||
|
|
||
|
if (/^[a-z]+$/.test(selector)) {
|
||
|
nodes = document.getElementsByTagName(selector);
|
||
|
} else if (/^\.[\w-]+$/.test(selector)) {
|
||
|
nodes = document.getElementsByClassName(selector.slice(1));
|
||
|
} else if (document.querySelectorAll) {
|
||
|
nodes = document.querySelectorAll(selector);
|
||
|
} else {
|
||
|
nodes = [];
|
||
|
}
|
||
|
|
||
|
for (var i = 0, children; i < nodes.length; i++) {
|
||
|
children = nodes[i].childNodes;
|
||
|
|
||
|
for (var j = 0, str; j < children.length; j++) {
|
||
|
code = children[j];
|
||
|
|
||
|
if (code.length >= 0) { // It's a text node
|
||
|
// Don't highlight command-line snippets
|
||
|
if (! /^\$/.test(code.nodeValue.trim())) {
|
||
|
syntax.forEach(function (s) {
|
||
|
var k = s[0], v = s[1];
|
||
|
code.nodeValue = code.nodeValue.replace(v, function (_, m) {
|
||
|
return '\u00ab' + encode(k) + '\u00b7'
|
||
|
+ encode(m) +
|
||
|
'\u00b7' + encode(k) + '\u00bb';
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for (var i = 0; i < nodes.length; i++) {
|
||
|
nodes[i].innerHTML =
|
||
|
nodes[i].innerHTML.replace(/\u00ab(.+?)\u00b7(.+?)\u00b7\1\u00bb/g, function (_, name, value) {
|
||
|
value = value.replace(/\u00ab[^\u00b7]+\u00b7/g, '').replace(/\u00b7[^\u00bb]+\u00bb/g, '');
|
||
|
return '<span class="' + decode(name) + '">' + escape(decode(value)) + '</span>';
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function escape(str) {
|
||
|
return str.replace(/</g, '<').replace(/>/g, '>');
|
||
|
}
|
||
|
|
||
|
// Encode ASCII characters to, and from Braille
|
||
|
function encode (str, encoded) {
|
||
|
table[encoded = str.split('').map(function (s) {
|
||
|
if (s.charCodeAt(0) > 127) { return s }
|
||
|
return String.fromCharCode(s.charCodeAt(0) + 0x2800);
|
||
|
}).join('')] = str;
|
||
|
return encoded;
|
||
|
}
|
||
|
function decode (str) {
|
||
|
if (str in table) {
|
||
|
return table[str];
|
||
|
} else {
|
||
|
return str.trim().split('').map(function (s) {
|
||
|
if (s.charCodeAt(0) - 0x2800 > 127) { return s }
|
||
|
return String.fromCharCode(s.charCodeAt(0) - 0x2800);
|
||
|
}).join('');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
})(window.hijs);
|
||
|
</script>
|
||
|
</body>
|