diff --git a/static/js/search.js b/static/js/search.js index 66db3e012e..717a93c579 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -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' ]; }