From e2e01effa64341d3653c735981760574739809b4 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Fri, 3 Jan 2020 22:44:04 +0100 Subject: [PATCH] Add fuzzy search if no results were found --- assets/js/just-the-docs.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assets/js/just-the-docs.js b/assets/js/just-the-docs.js index 666f442..ac24dd2 100644 --- a/assets/js/just-the-docs.js +++ b/assets/js/just-the-docs.js @@ -154,6 +154,15 @@ function searchLoaded(index, docs) { }); }); + if ((results.length == 0) && (input.length > 2)) { + results = index.query(function (query) { + var tokens = lunr.tokenizer(input) + query.term(tokens, { + editDistance: Math.round(Math.sqrt(input.length / 2 - 1)) + }); + }); + } + if (results.length == 0) { var noResultsDiv = document.createElement('div'); noResultsDiv.classList.add('search-no-result');