From c83581cf47c5bfa9c37b364993a88990407653f7 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Thu, 30 Sep 2021 08:07:15 -0400 Subject: [PATCH] improve search --- docs/assets/plugins/search/search.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/assets/plugins/search/search.js b/docs/assets/plugins/search/search.js index 097097cf..160cb5cd 100644 --- a/docs/assets/plugins/search/search.js +++ b/docs/assets/plugins/search/search.js @@ -221,7 +221,12 @@ await searchIndex; const hasQuery = query.length > 0; - const matches = hasQuery ? searchIndex.search(`${query}~2`) : []; + let matches = hasQuery ? searchIndex.search(`${query}`) : []; + + // Fall back to a fuzzy search if no matches are found + if (matches.length === 0 && hasQuery) { + matches = searchIndex.search(`${query}~2`); + } let hasResults = hasQuery && matches.length > 0; siteSearch.classList.toggle('site-search--has-results', hasQuery && hasResults);