mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
search: long search terms causing browser freeze #408
This commit is contained in:
parent
39b8347b1f
commit
9c1233d9e3
1 changed files with 13 additions and 1 deletions
|
@ -123,11 +123,23 @@ function search(term) {
|
|||
}
|
||||
|
||||
function searchPatterns(word) {
|
||||
// for short words high amounts of typos doesn't make sense
|
||||
// for long words we allow less typos because this largly increases search time
|
||||
var typos = [
|
||||
{ len: -1, typos: 1 },
|
||||
{ len: 60, typos: 2 },
|
||||
{ len: 40, typos: 3 },
|
||||
{ len: 20, typos: 4 },
|
||||
{ len: 16, typos: 3 },
|
||||
{ len: 12, typos: 2 },
|
||||
{ len: 8, typos: 1 },
|
||||
{ len: 4, typos: 0 },
|
||||
];
|
||||
return [
|
||||
word + '^100',
|
||||
word + '*^10',
|
||||
'*' + word + '^10',
|
||||
word + '~' + Math.floor(word.length / 4) + '^1' // allow 1 in 4 letters to have a typo
|
||||
word + '~' + typos.reduce( function( a, c, i ){ return word.length < c.len ? c : a; } ).typos + '^1'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue