diff options
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/completion.js b/lib/completion.js index d6a901ae..d0c798c8 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -21,16 +21,23 @@ var completion = (function() { } /** Calculates a very simple similarity value between a :query and a :string. The current - * implementation simply returns the length of the longest prefix of :query that is found within :str. + * implementation simply returns the cumulated length of query parts that are also in the string. */ self.calculateRelevancy = function(query, str) { query = self.normalize(query); str = self.normalize(str); - for (var i = query.length; i >= 0; --i) { - if (str.indexOf(query.slice(0, i)) >= 0) - return i; + var sum = 0; + // only iterate over slices of the query starting at an offset up to 10 to save resources + for (var start = 0; start < 10; ++start) { + for (var i = query.length; i >= start; --i) { + if (str.indexOf(query.slice(start, i)) >= 0) { + sum += i - start; + break; + } + + } } - return 0; + return sum; } /** Trims the size of the regex cache to the configured size using a FIFO algorithm. */ |
