This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): refactor the docs app search for better bootup time
This commit refactors how the search index is built. The docsSearch service is now defined by a provider, which returns a different implementation of the service depending upon whether the current browser supports WebWorkers or now. * **WebWorker supported**: The index is then built and stored in a new worker. The service posts and receives messages to and from this worker to make queries on the search index. * **WebWorker no supported**: The index is built locally but with a 500ms delay so that the initial page can render before the browser is blocked as the index is built. Also the way that the current app is identified has been modified so we can slim down the js data files (pages-data.js) to again improve startup time. Closes #9204 Closes #9203
- Loading branch information
1 parent
e6996cc
commit d5c0412
Showing
19 changed files
with
260 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
/* jshint browser: true */ | ||
/* global importScripts, onmessage: true, postMessage, lunr */ | ||
|
||
// Load up the lunr library | ||
importScripts('../components/lunr.js-0.4.2/lunr.min.js'); | ||
|
||
// Create the lunr index - the docs should be an array of object, each object containing | ||
// the path and search terms for a page | ||
var index = lunr(function() { | ||
this.ref('path'); | ||
this.field('titleWords', {boost: 50}); | ||
this.field('members', { boost: 40}); | ||
this.field('keywords', { boost : 20 }); | ||
}); | ||
|
||
// Retrieve the searchData which contains the information about each page to be indexed | ||
var searchData = {}; | ||
var searchDataRequest = new XMLHttpRequest(); | ||
searchDataRequest.onload = function() { | ||
|
||
// Store the pages data to be used in mapping query results back to pages | ||
searchData = JSON.parse(this.responseText); | ||
// Add search terms from each page to the search index | ||
searchData.forEach(function(page) { | ||
index.add(page); | ||
}); | ||
postMessage({ e: 'index-ready' }); | ||
}; | ||
searchDataRequest.open('GET', 'search-data.json'); | ||
searchDataRequest.send(); | ||
|
||
// The worker receives a message everytime the web app wants to query the index | ||
onmessage = function(oEvent) { | ||
var q = oEvent.data.q; | ||
var hits = index.search(q); | ||
var results = []; | ||
// Only return the array of paths to pages | ||
hits.forEach(function(hit) { | ||
results.push(hit.ref); | ||
}); | ||
// The results of the query are sent back to the web app via a new message | ||
postMessage({ e: 'query-ready', q: q, d: results }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.