2 importScripts('lunr.min.js');
9 lunr.tokenizer.seperator = /[\s\-\.]+/;
11 var stopWordsRequest = new XMLHttpRequest();
12 stopWordsRequest.open('GET', '../search-stopwords.json');
13 stopWordsRequest.onload = function () {
14 if (this.status != 200) {
17 stopWords = JSON.parse(this.responseText);
20 stopWordsRequest.send();
22 var searchDataRequest = new XMLHttpRequest();
24 searchDataRequest.open('GET', '../index.json');
25 searchDataRequest.onload = function () {
26 if (this.status != 200) {
29 searchData = JSON.parse(this.responseText);
33 postMessage({ e: 'index-ready' });
35 searchDataRequest.send();
37 onmessage = function (oEvent) {
38 var q = oEvent.data.q;
39 var hits = lunrIndex.search(q);
41 hits.forEach(function (hit) {
42 var item = searchData[hit.ref];
43 results.push({ 'href': item.href, 'title': item.title, 'keywords': item.keywords });
45 postMessage({ e: 'query-ready', q: q, d: results });
48 function buildIndex() {
49 if (stopWords !== null && !isEmpty(searchData)) {
50 lunrIndex = lunr(function () {
51 this.pipeline.remove(lunr.stopWordFilter);
53 this.field('title', { boost: 50 });
54 this.field('keywords', { boost: 20 });
56 for (var prop in searchData) {
57 if (searchData.hasOwnProperty(prop)) {
58 this.add(searchData[prop]);
62 var docfxStopWordFilter = lunr.generateStopWordFilter(stopWords);
63 lunr.Pipeline.registerFunction(docfxStopWordFilter, 'docfxStopWordFilter');
64 this.pipeline.add(docfxStopWordFilter);
65 this.searchPipeline.add(docfxStopWordFilter);
70 function isEmpty(obj) {
73 for (var prop in obj) {
74 if (obj.hasOwnProperty(prop))