search: long search terms causing browser freeze #408

This commit is contained in:
Sören Weber 2022-11-29 19:25:40 +01:00
parent 39b8347b1f
commit 9c1233d9e3
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -123,11 +123,23 @@ function search(term) {
} }
function searchPatterns(word) { 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 [ return [
word + '^100', word + '^100',
word + '*^10', word + '*^10',
'*' + 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'
]; ];
} }