From a10bca718b382296e66049c346c379a4dc8d3b4f Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Mon, 6 Feb 2023 13:02:00 +0000 Subject: [PATCH] change fuse options to improve search --- search.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/search.js b/search.js index a85de1c..7c5e73d 100644 --- a/search.js +++ b/search.js @@ -19,21 +19,25 @@ const fuse = new Fuse(data, { }, { name: TITLE, - weight: 1 + weight: 4 } ], - includeMatches: true + includeMatches: true, + useExtendedSearch: true, + ignoreLocation: true, + threshhold: 0.4, }) +const RESULTS_MAX = 5 + const searchBar = document.getElementById('search') -const resultsMax = document.getElementById('resultsMax') const resultsDiv = document.getElementById('results') var results = [] function updateResults() { resultsDiv.innerHTML = '' - results = fuse.search(searchBar.value).slice(0, parseInt(resultsMax.value)) + results = fuse.search(searchBar.value, { limit: RESULTS_MAX }) results.forEach(r => { wrapper = document.createElement('div') wrapper.className = "article" @@ -99,8 +103,6 @@ searchBar.addEventListener('keyup', e => { }) searchBar.addEventListener('change', updateResults) -resultsMax.addEventListener('keyup', updateResults) -resultsMax.addEventListener('change', updateResults) const searchParams = new URL(window.location.href).searchParams; searchBar.value = searchParams.get('q');