mirror of
https://github.com/alvierahman90/gronk.git
synced 2024-11-25 08:29:53 +00:00
change fuse options to improve search
This commit is contained in:
parent
18ea2a3b04
commit
a10bca718b
14
search.js
14
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');
|
||||
|
Loading…
Reference in New Issue
Block a user