Skip to content

Commit 9cf85e8

Browse files
committed
Add support for DEBUG_SEARCH_WEIGHTS
1 parent 7993ce7 commit 9cf85e8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.config/typedoc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@
2828
"external": false,
2929
"@internal": false
3030
},
31+
"searchGroupBoosts": {
32+
"Classes": 2.0,
33+
"Interfaces": 2.0,
34+
"Enumerations": 2.0,
35+
"Type Aliases": 2.0
36+
},
37+
"searchInComments": true,
3138
"logLevel": "Verbose"
3239
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Features
4+
5+
- The `DEBUG_SEARCH_WEIGHTS` global variable can now be set on `window` to add search scoring information in the search results.
6+
37
## v0.23.4 (2022-07-02)
48

59
### Bug Fixes

src/lib/output/themes/default/assets/typedoc/components/Search.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function updateResults(
169169
// boost by exact match on name
170170
if (row.name.toLowerCase().startsWith(searchText.toLowerCase())) {
171171
boost *=
172-
1 + 1 / (Math.abs(row.name.length - searchText.length) * 10);
172+
1 + 1 / (1 + Math.abs(row.name.length - searchText.length));
173173
}
174174

175175
item.score *= boost;
@@ -182,6 +182,9 @@ function updateResults(
182182

183183
// Bold the matched part of the query in the search results
184184
let name = boldMatches(row.name, searchText);
185+
if (globalThis.DEBUG_SEARCH_WEIGHTS) {
186+
name += ` (score: ${res[i].score.toFixed(2)})`;
187+
}
185188
if (row.parent) {
186189
name = `<span class="parent">${boldMatches(
187190
row.parent,

0 commit comments

Comments
 (0)