Skip to content

Commit f2d2abe

Browse files
Michael YoderGerrit0
Michael Yoder
authored andcommittedSep 16, 2023
Handling for multi word searches
Split searches on space and wraps each part in a wildcard. This replaces the current current behavior of wrapping the entire search query in a wildcard. Current behavior: * "create" becomes "*create*" * "create item" becomes "*create item*" New behavior: * "create" becomes "*create*" * "create item" becomes "*create* *item*"
1 parent 5e4c79d commit f2d2abe

File tree

1 file changed

+16
-3
lines changed
  • src/lib/output/themes/default/assets/typedoc/components

1 file changed

+16
-3
lines changed
 

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,22 @@ function updateResults(
157157
const searchText = query.value.trim();
158158

159159
// Perform a wildcard search
160-
// Set empty `res` to prevent getting random results with wildcard search
161-
// when the `searchText` is empty.
162-
let res = searchText ? state.index.search(`*${searchText}*`) : [];
160+
let res: Index.Result[];
161+
if (searchText) {
162+
// Create a wildcard out of space-separated words in the query,
163+
// ignoring any extra spaces
164+
const searchWithWildcards = searchText
165+
.split(" ")
166+
.map((x) => {
167+
return x.length ? `*${x}*` : "";
168+
})
169+
.join(" ");
170+
res = state.index.search(searchWithWildcards);
171+
} else {
172+
// Set empty `res` to prevent getting random results with wildcard search
173+
// when the `searchText` is empty.
174+
res = [];
175+
}
163176

164177
for (let i = 0; i < res.length; i++) {
165178
const item = res[i];

0 commit comments

Comments
 (0)
Please sign in to comment.