diff options
| author | Niklas Baumstark | 2012-01-21 13:36:03 +0100 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:54:36 +0200 |
| commit | 0bcad9357ad0a774ce2190f1e990dcdd17762c2a (patch) | |
| tree | 96f7236b4ba5d9027d74cc2ff443b972c6282c29 /lib/completion.js | |
| parent | 8f126b03e6644be45c9b046fb1a1a682f95eb085 (diff) | |
| download | vimium-0bcad9357ad0a774ce2190f1e990dcdd17762c2a.tar.bz2 | |
improve relevancy calculation
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. */ |
