Skip to content

Commit 0175187

Browse files
docs: improve search for documentation (#6952)
* docs: update search to aio search * chore: use custom stop word filter for lunr * docs: applay review suggestions * docs: remove stop word filtering during search * docs: improve first search query to search only in title * docs: remove deprecated import paths from search results * chore: commit package-lock.json --------- Co-authored-by: Mladen Jakovljević <jakovljevic.mladen@gmail.com>
1 parent 2e1ca19 commit 0175187

16 files changed

Lines changed: 1364 additions & 1058 deletions

docs_app/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,5 @@ protractor-results*.txt
4646
.DS_Store
4747
Thumbs.db
4848

49-
# copied dependencies
50-
src/assets/js/lunr*
51-
5249
assets/images/svgs/*
5350
!assets/images/svgs/.gitkeep

docs_app/angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"index": "src/index.html",
1616
"main": "src/main.ts",
1717
"tsConfig": "src/tsconfig.app.json",
18+
"webWorkerTsConfig": "tsconfig.worker.json",
1819
"namedChunks": true,
1920
"polyfills": "src/polyfills.ts",
2021
"assets": [

docs_app/package-lock.json

Lines changed: 33 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs_app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"author": "RxJS",
77
"license": "MIT",
88
"scripts": {
9-
"postinstall": "uglifyjs node_modules/lunr/lunr.js -c -m -o src/assets/js/lunr.min.js --source-map",
109
"ng": "ng",
1110
"firebase": "firebase",
1211
"start": "ng serve --configuration=fast",
@@ -73,6 +72,7 @@
7372
"@swirly/types": "^0.18.1",
7473
"@types/jasmine": "~3.6.0",
7574
"@types/jasminewd2": "^2.0.3",
75+
"@types/lunr": "^2.3.3",
7676
"@types/node": "^12.11.1",
7777
"@types/svgo": "^1.3.3",
7878
"archiver": "^3.0.0",
@@ -118,13 +118,13 @@
118118
"rimraf": "^2.6.1",
119119
"semver": "^6.1.1",
120120
"shelljs": "^0.8.3",
121+
"stemmer": "^2.0.0",
121122
"svgo": "^1.3.2",
122123
"svgson": "^4.1.0",
123124
"tree-kill": "^1.2.2",
124125
"ts-node": "^8.2.0",
125126
"tslint": "~6.1.0",
126127
"typescript": "4.5.4",
127-
"uglify-js": "^3.6.0",
128128
"unist-util-filter": "^1.0.2",
129129
"unist-util-source": "^1.0.5",
130130
"unist-util-visit": "^1.4.1",

docs_app/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class AppComponent implements OnInit {
200200
// Do not initialize the search on browsers that lack web worker support
201201
if ('Worker' in window) {
202202
// Delay initialization by up to 2 seconds
203-
this.searchService.initWorker('app/search/search-worker.js', 2000);
203+
this.searchService.initWorker(2000);
204204
}
205205

206206
this.onResize(window.innerWidth);

docs_app/src/app/search/search-worker.js

Lines changed: 0 additions & 103 deletions
This file was deleted.

docs_app/src/app/search/search.service.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,19 @@ export class SearchService {
2222
* initial rendering of the web page. Triggering a search will override this delay and cause the index to be
2323
* loaded immediately.
2424
*
25-
* @param workerUrl the url of the WebWorker script that runs the searches
2625
* @param initDelay the number of milliseconds to wait before we load the WebWorker and generate the search index
2726
*/
28-
initWorker(workerUrl: string, initDelay: number) {
27+
initWorker(initDelay: number) {
2928
// Wait for the initDelay or the first search
30-
const ready = this.ready = race<any>(
31-
timer(initDelay),
32-
this.searchesSubject.asObservable().pipe(first()),
33-
)
34-
.pipe(
35-
concatMap(() => {
36-
// Create the worker and load the index
37-
this.worker = WebWorkerClient.create(workerUrl, this.zone);
38-
return this.worker.sendMessage<boolean>('load-index');
39-
}),
40-
publishReplay(1),
41-
);
29+
const ready = (this.ready = race<any>(timer(initDelay), this.searchesSubject.asObservable().pipe(first())).pipe(
30+
concatMap(() => {
31+
// Create the worker and load the index
32+
const worker = new Worker(new URL('./search.worker', import.meta.url), { type: 'module' });
33+
this.worker = WebWorkerClient.create(worker, this.zone);
34+
return this.worker.sendMessage<boolean>('load-index');
35+
}),
36+
publishReplay(1)
37+
));
4238

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

4844
/**
4945
* Search the index using the given query and emit results on the observable that is returned.
46+
*
5047
* @param query The query to run against the index.
5148
* @returns an observable collection of search results
5249
*/

0 commit comments

Comments
 (0)