Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve search for documentation #6952

Merged
merged 7 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs_app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@ protractor-results*.txt
.DS_Store
Thumbs.db

# copied dependencies
src/assets/js/lunr*

assets/images/svgs/*
!assets/images/svgs/.gitkeep
1 change: 1 addition & 0 deletions docs_app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"webWorkerTsConfig": "tsconfig.worker.json",
"namedChunks": true,
"polyfills": "src/polyfills.ts",
"assets": [
Expand Down
54 changes: 33 additions & 21 deletions docs_app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"author": "RxJS",
"license": "MIT",
"scripts": {
"postinstall": "uglifyjs node_modules/lunr/lunr.js -c -m -o src/assets/js/lunr.min.js --source-map",
"ng": "ng",
"firebase": "firebase",
"start": "ng serve --configuration=fast",
Expand Down Expand Up @@ -73,6 +72,7 @@
"@swirly/types": "^0.18.1",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "^2.0.3",
"@types/lunr": "^2.3.3",
"@types/node": "^12.11.1",
"@types/svgo": "^1.3.3",
"archiver": "^3.0.0",
Expand Down Expand Up @@ -118,13 +118,13 @@
"rimraf": "^2.6.1",
"semver": "^6.1.1",
"shelljs": "^0.8.3",
"stemmer": "^2.0.0",
"svgo": "^1.3.2",
"svgson": "^4.1.0",
"tree-kill": "^1.2.2",
"ts-node": "^8.2.0",
"tslint": "~6.1.0",
"typescript": "4.5.4",
"uglify-js": "^3.6.0",
"unist-util-filter": "^1.0.2",
"unist-util-source": "^1.0.5",
"unist-util-visit": "^1.4.1",
Expand Down
2 changes: 1 addition & 1 deletion docs_app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class AppComponent implements OnInit {
// Do not initialize the search on browsers that lack web worker support
if ('Worker' in window) {
// Delay initialization by up to 2 seconds
this.searchService.initWorker('app/search/search-worker.js', 2000);
this.searchService.initWorker(2000);
}

this.onResize(window.innerWidth);
Expand Down
103 changes: 0 additions & 103 deletions docs_app/src/app/search/search-worker.js

This file was deleted.

25 changes: 11 additions & 14 deletions docs_app/src/app/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@ export class SearchService {
* initial rendering of the web page. Triggering a search will override this delay and cause the index to be
* loaded immediately.
*
* @param workerUrl the url of the WebWorker script that runs the searches
* @param initDelay the number of milliseconds to wait before we load the WebWorker and generate the search index
*/
initWorker(workerUrl: string, initDelay: number) {
initWorker(initDelay: number) {
// Wait for the initDelay or the first search
const ready = this.ready = race<any>(
timer(initDelay),
this.searchesSubject.asObservable().pipe(first()),
)
.pipe(
concatMap(() => {
// Create the worker and load the index
this.worker = WebWorkerClient.create(workerUrl, this.zone);
return this.worker.sendMessage<boolean>('load-index');
}),
publishReplay(1),
);
const ready = (this.ready = race<any>(timer(initDelay), this.searchesSubject.asObservable().pipe(first())).pipe(
concatMap(() => {
// Create the worker and load the index
const worker = new Worker(new URL('./search.worker', import.meta.url), { type: 'module' });
this.worker = WebWorkerClient.create(worker, this.zone);
return this.worker.sendMessage<boolean>('load-index');
}),
publishReplay(1)
));

// Connect to the observable to kick off the timer
(ready as ConnectableObservable<boolean>).connect();
Expand All @@ -47,6 +43,7 @@ export class SearchService {

/**
* Search the index using the given query and emit results on the observable that is returned.
*
* @param query The query to run against the index.
* @returns an observable collection of search results
*/
Expand Down
Loading