Skip to content

Commit

Permalink
Handling for multi word searches
Browse files Browse the repository at this point in the history
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*"
  • Loading branch information
Michael Yoder authored and Gerrit0 committed Sep 16, 2023
1 parent 5e4c79d commit f2d2abe
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib/output/themes/default/assets/typedoc/components/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,22 @@ function updateResults(
const searchText = query.value.trim();

// Perform a wildcard search
// Set empty `res` to prevent getting random results with wildcard search
// when the `searchText` is empty.
let res = searchText ? state.index.search(`*${searchText}*`) : [];
let res: Index.Result[];
if (searchText) {
// Create a wildcard out of space-separated words in the query,
// ignoring any extra spaces
const searchWithWildcards = searchText
.split(" ")
.map((x) => {
return x.length ? `*${x}*` : "";
})
.join(" ");
res = state.index.search(searchWithWildcards);
} else {
// Set empty `res` to prevent getting random results with wildcard search
// when the `searchText` is empty.
res = [];
}

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

0 comments on commit f2d2abe

Please sign in to comment.