Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 2881b05

Browse files
committed
fix(Search): Partial revert of search to search.js again
See: TypeStrong/typedoc@f0af1f1 TypeStrong/typedoc-default-themes@0fa4edd d78a87c Partially addresses actions-on-google/assistant-conversation-nodejs#32 Fixes #69 Change-Id: I1151cf508f160a2f4f86bbc68e54572aafedb2d7
1 parent 305ce9d commit 2881b05

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

third_party/src/default/assets/js/src/typedoc/components/Search.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,16 @@ module typedoc.search {
111111
setLoadingState(SearchLoadingState.Failure);
112112
return;
113113
}
114-
fetch(url)
115-
.then(response => {
116-
if (!response.ok) {
117-
throw new Error('The search index is missing');
118-
}
119114

120-
return response.json();
121-
})
122-
.then((source: IData) => {
123-
data = source;
124-
index = lunr.Index.load(source.index);
125-
126-
initializePriorityResults();
127-
setLoadingState(SearchLoadingState.Ready);
128-
})
129-
.catch((error) => {
130-
setLoadingState(SearchLoadingState.Failure);
131-
});
115+
try {
116+
data = window['searchData']
117+
index = lunr.Index.load(data.index);
118+
119+
initializePriorityResults();
120+
setLoadingState(SearchLoadingState.Ready);
121+
} catch (e) {
122+
setLoadingState(SearchLoadingState.Failure);
123+
}
132124
}
133125

134126
/**
@@ -142,7 +134,9 @@ module typedoc.search {
142134
if (loadingState !== SearchLoadingState.Ready) return
143135
$results.empty()
144136

145-
const res = index.search(query)
137+
// Fuzzy match
138+
// See https://lunrjs.com/docs/lunr.Index.html#~QueryString
139+
const res = index.search(`*${query}*`)
146140
for (let i = 0, c = Math.min(10, res.length); i < c; i++) {
147141
const row = data.rows[res[i].ref]
148142
let name = row.name

third_party/src/default/layouts/default.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<link rel="stylesheet" href="{{path}}">
1919
{{/each}}
2020
{{/if}}
21+
<script async src="{{relativeURL "assets/js/search.js"}}" id="search-script"></script>
2122
</head>
2223
<body>
2324

0 commit comments

Comments
 (0)