Skip to content

Commit bab2eb9

Browse files
authored
chore: Remove unused localsearch function from default template (#9201)
* chore: remove unused localsearch function * chore: add missing semicolon
1 parent fecdfbb commit bab2eb9

File tree

1 file changed

+8
-47
lines changed

1 file changed

+8
-47
lines changed

templates/default/styles/docfx.js

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,10 @@ $(function () {
128128
return;
129129
}
130130
try {
131-
var worker = new Worker(relHref + 'styles/search-worker.min.js');
132-
if (!worker && !window.worker) {
133-
localSearch();
134-
} else {
135-
webWorkerSearch();
131+
if(!window.Worker){
132+
return;
136133
}
137-
134+
webWorkerSearch();
138135
renderSearchBox();
139136
highlightKeywords();
140137
addSearchEvent();
@@ -164,50 +161,14 @@ $(function () {
164161
}
165162
}
166163

167-
// Search factory
168-
function localSearch() {
169-
console.log("using local search");
170-
var lunrIndex = lunr(function () {
171-
this.ref('href');
172-
this.field('title', { boost: 50 });
173-
this.field('keywords', { boost: 20 });
174-
});
175-
lunr.tokenizer.seperator = /[\s\-\.]+/;
176-
var searchData = {};
177-
var searchDataRequest = new XMLHttpRequest();
178-
179-
var indexPath = relHref + "index.json";
180-
if (indexPath) {
181-
searchDataRequest.open('GET', indexPath);
182-
searchDataRequest.onload = function () {
183-
if (this.status != 200) {
184-
return;
185-
}
186-
searchData = JSON.parse(this.responseText);
187-
for (var prop in searchData) {
188-
if (searchData.hasOwnProperty(prop)) {
189-
lunrIndex.add(searchData[prop]);
190-
}
191-
}
192-
}
193-
searchDataRequest.send();
194-
}
195-
196-
$("body").bind("queryReady", function () {
197-
var hits = lunrIndex.search(query);
198-
var results = [];
199-
hits.forEach(function (hit) {
200-
var item = searchData[hit.ref];
201-
results.push({ 'href': item.href, 'title': item.title, 'keywords': item.keywords });
202-
});
203-
handleSearchResults(results);
204-
});
205-
}
206-
207164
function webWorkerSearch() {
208-
console.log("using Web Worker");
209165
var indexReady = $.Deferred();
210166

167+
var worker = new Worker(relHref + 'styles/search-worker.min.js');
168+
worker.onerror = function (oEvent) {
169+
console.error('Error occurred at search-worker. message: ' + oEvent.message);
170+
}
171+
211172
worker.onmessage = function (oEvent) {
212173
switch (oEvent.data.e) {
213174
case 'index-ready':

0 commit comments

Comments
 (0)