Add fuzzy search if no results were found

This commit is contained in:
Silvio Giebl 2020-01-03 22:44:04 +01:00
parent b13b44f18b
commit e2e01effa6
1 changed files with 9 additions and 0 deletions

View File

@ -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');